Page 1 of 1

Array initializing .cpp an .h files

Posted: Tue Aug 26, 2008 5:08 pm
by Dragonazul
Hi all,

I want to create an array of nodes in a class of my application.
Into the .h file of the class I have:

Code: Select all

core::array<scene::ISceneNode*> arrayNodes;
and into the constructor into the .cpp file:

Code: Select all

this->arrayNodes = new core::array<scene::ISceneNode*>::array(10);

I get this compile error:

Code: Select all

1>h:\apli\src\apli.cpp(24) : error C2061: syntax error : identifier '{ctor}'
I have no {ctor} into my code. If I comment the line into the .h and into the .cpp the aplication run ok.

If I execute the application without initializing the array, the application breaks when it acced to the class.

How should it be created?

Thanks

Re: Array initializing .cpp an .h files

Posted: Tue Aug 26, 2008 6:16 pm
by rogerborg
I'll explain what's going wrong:
Dragonazul wrote:

Code: Select all

core::array<scene::ISceneNode*> arrayNodes;
This is an array object, not a pointer to an array object.
Dragonazul wrote:

Code: Select all

this->arrayNodes = new core::array<scene::ISceneNode*>::array(10);
And this is trying to create 10 array objects (not an array of 10 objects) and assign a pointer to those objects to your array object, which is so wrong that it's almost right. In Bizarro World.

It looks like you just want to set the capacity of the array to 10. If so, then it's just:

Code: Select all

this->arrayNodes.set_used(10);

Re: Array initializing .cpp an .h files

Posted: Tue Aug 26, 2008 7:17 pm
by Acki
Dragonazul wrote:I have no {ctor} into my code.
I guess {ctor} means constructor... :lol:

Posted: Wed Aug 27, 2008 1:05 pm
by torleif
Shhh, here's a secret: the array in irrlicht is actually a vector.

Code: Select all

core::array<scene::ISceneNode*> arrayNodes;

arrayNodes.push_back(new ISeneNode("heh, use smgr"));
arrayNodes.push_back(new ISeneNode("lol dosn't rlly wrk"));

std::cout <<"Will print out 2 if correct : "<< arrayNodes.size() << "\n";

Posted: Wed Aug 27, 2008 2:02 pm
by arras
Yes it is.

Posted: Wed Aug 27, 2008 5:04 pm
by Dragonazul
Thanks for the help, it works.

Now I have my array :)