Array initializing .cpp an .h files

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Dragonazul
Posts: 24
Joined: Sun Sep 23, 2007 9:45 pm
Location: Spain

Array initializing .cpp an .h files

Post 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
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: Array initializing .cpp an .h files

Post 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);
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Array initializing .cpp an .h files

Post by Acki »

Dragonazul wrote:I have no {ctor} into my code.
I guess {ctor} means constructor... :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
torleif
Posts: 188
Joined: Mon Jun 30, 2008 4:53 am

Post 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";
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Yes it is.
Dragonazul
Posts: 24
Joined: Sun Sep 23, 2007 9:45 pm
Location: Spain

Post by Dragonazul »

Thanks for the help, it works.

Now I have my array :)
Post Reply