Declaration of a Dynamic Array of Objects


hi guys,

embarrassingly, i'm having little trouble declaring global array of objects dynamically.

right i've gotten following working:

sketch
code: [select]

#include "myclass.h"
#define rows 3
myclass arr[rows];


header
code: [select]

#ifndef myclass_h
#define myclass_h
#include "wprogram.h"

class myclass {
 public:
   myclass();
   myclass(int var);
   int getvar();

 private:
   int _var;
};
#endif


you can guess myclass.cpp file looks like.

however, if try dynamically,

sketch
code: [select]
#include "myclass.h"
#define rows 3

myclass *arr;
void setup() {
 for(int = 0; < rows; i++) {
   arr[i] = new myclass;
 }
}

i error
code: [select]
error: invalid conversion 'myclass *' 'int'



i trying on project of mine, , received
code: [select]
undefined reference 'operator new[](unsigned int)'
i've done quite bit of searching earlier , unable find stuck @ similar spot.

many in advance!

"new" doesn't work on arduino.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Declaration of a Dynamic Array of Objects


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums