Pointer to pointer array of scene nodes

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.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Pointer to pointer array of scene nodes

Post by robmar »

I just can´t figure out the syntax to do this and not get errors!

irr::scene::ILightSceneNode (*m_pLights)[MAX_LIGHTS]; // Does not work for some reason! Abstract class not allowed!!

This is meant to be a point to an array of pointers, so this pointer can be initialised and passed to the OnSetConstants callback.

I´ve googled and there are lots of threads about this, it works fine with ints, etc., but not with void ptrs or scene node pointers!

Help!!
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: Pointer to pointer array of scene nodes

Post by polylux »

Well, pretty obvious to me, as you should be omitting the brackets.
Like so:

Code: Select all

scene::ILightSceneNode* m_pLights[MAX_LIGHTS];
Otherwise the compiler tries to dereference m_pLights which won't work at that stage.
Or do I get your intention wrong?
beer->setMotivationCallback(this);
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Ahhh ha, think again!!

that makes it an array of pointers, where what I need is a single pointer to an array of pointers!

officially, the brackets separate the left-right array effect, and make it a pointer to an array of pointers.

if you swap the lightscenenode for an int*, it works fine, or I can list say 8 separate pointers to lightscenenodes, but how to do it in a tidy pointer to array?
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: Pointer to pointer array of scene nodes

Post by polylux »

Well, the above is of type

Code: Select all

scene::ILightSceneNode**
Isn't that what you want?
beer->setMotivationCallback(this);
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Its a ptr to a ptr, but not a ptr to a ptr-array!

Like this works, its similar, but its a series of ptrs to ptrs:

irr::scene::ILightSceneNode **m_pLightNode1;
irr::scene::ILightSceneNode **m_pLightNode2;
irr::scene::ILightSceneNode **m_pLightNode3;
...
//irr::scene::ILightSceneNode (*m_pLights)[MAX_LIGHTS]; // Does not work for some reason! Abstract class not allowed!! Works with ints though!

then...

if ( m_pLightNode1 && *m_pLightNode1 )
m_LightPosition = (*m_pLightNode1)->getAbsolutePosition();

but for neatness, and to use it in a while or for loop, I need a ptr to a ptr-array, but how is that done?
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: Pointer to pointer array of scene nodes

Post by polylux »

Sry, but that thing up there as I posted it is a pointer array. Dunno what else you want. Also I don't really get your latest example.
beer->setMotivationCallback(this);
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Tried this:-

irr::scene::ILightSceneNode **m_pLightNodes[MAX_LIGHTS]; // Pointer to an array of ptrs....???

with

m_LightPosition = *(*m_pLightNodes[0])->getAbsolutePosition(); // Intelisense shows all the members!!!

but then get "error C2100: illegal indirection"
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: Pointer to pointer array of scene nodes

Post by polylux »

Why not do it this:

Code: Select all

scene::ILightSceneNode* m_pLightNodes[MAX_LIGHTS]; //that bugger here _IS_ a pointer array
core::vector3df pos = m_pLightNodes[0]->getAbsolutePosition();
Guess you just have to get your pointer syntax (and arithmetics) right.
beer->setMotivationCallback(this);
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

The problem is that the array of pointers is in a class that onsetconstants cannot access unless I setup the class headers in onsetconstants, which I didn´t want to do.

So I need to simply pass a pointer to the "array of pointers" that is in my main class, to the onsetconstants class.

How do I pass a pointer to an array of pointers is the question!!

Not how do I create an array of pointers and use it directly... there is.. a difference!!
Abraxas)
Posts: 227
Joined: Sun Oct 18, 2009 7:24 am

Re: Pointer to pointer array of scene nodes

Post by Abraxas) »

Unless I misunderstand, a pointer and an array variable are the same thing. If you had an array with 2 members, your pointer variable++ would be the second member.

I'm not 100% sure about pointer arithmetic because I stay away from code grammar that isn't obvious to another person reading it.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Pointer to pointer array of scene nodes

Post by CuteAlien »

Use the declaration as polylux posted and then pass m_pLights or &m_pLights[0] (those are identical). Then you pass the address of m_pLights.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Have you tried to do that with VS? It generates the errors I mentioned.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Pointer to pointer array of scene nodes

Post by serengeor »

robmar wrote:Have you tried to do that with VS? It generates the errors I mentioned.
http://msdn.microsoft.com/en-us/library ... s.71).aspx


Is this http://ideone.com/LrlgHP what you want to do?
Working on game: Marrbles (Currently stopped).
jaworekplay
Posts: 36
Joined: Mon Jan 23, 2012 11:14 pm
Location: Lancs, UK

Re: Pointer to pointer array of scene nodes

Post by jaworekplay »

+1 to polylux .
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

Thanks, took a look at those links, and its not error c2100, its just that the compiler does not allow ptrs to arrays of ptrs of abstract class, including even a simple void ptr!

Why it disallows a ptr to an array of void ptrs I can not imagine!!!

In the end I just changed to use a ptr to a ptr to an array of vector3df, and that works.
Post Reply