Pointer to pointer array of scene nodes
Pointer to pointer array of scene nodes
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!!
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!!
Re: Pointer to pointer array of scene nodes
Well, pretty obvious to me, as you should be omitting the brackets.
Like so:
Otherwise the compiler tries to dereference m_pLights which won't work at that stage.
Or do I get your intention wrong?
Like so:
Code: Select all
scene::ILightSceneNode* m_pLights[MAX_LIGHTS];
Or do I get your intention wrong?
beer->setMotivationCallback(this);
Re: Pointer to pointer array of scene nodes
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?
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?
Re: Pointer to pointer array of scene nodes
Well, the above is of type
Isn't that what you want?
Code: Select all
scene::ILightSceneNode**
beer->setMotivationCallback(this);
Re: Pointer to pointer array of scene nodes
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?
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?
Re: Pointer to pointer array of scene nodes
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);
Re: Pointer to pointer array of scene nodes
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"
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"
Re: Pointer to pointer array of scene nodes
Why not do it this:
Guess you just have to get your pointer syntax (and arithmetics) right.
Code: Select all
scene::ILightSceneNode* m_pLightNodes[MAX_LIGHTS]; //that bugger here _IS_ a pointer array
core::vector3df pos = m_pLightNodes[0]->getAbsolutePosition();
beer->setMotivationCallback(this);
Re: Pointer to pointer array of scene nodes
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!!
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!!
Re: Pointer to pointer array of scene nodes
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.
I'm not 100% sure about pointer arithmetic because I stay away from code grammar that isn't obvious to another person reading it.
Re: Pointer to pointer array of scene nodes
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Pointer to pointer array of scene nodes
Have you tried to do that with VS? It generates the errors I mentioned.
Re: Pointer to pointer array of scene nodes
http://msdn.microsoft.com/en-us/library ... s.71).aspxrobmar wrote:Have you tried to do that with VS? It generates the errors I mentioned.
Is this http://ideone.com/LrlgHP what you want to do?
Working on game: Marrbles (Currently stopped).
-
- Posts: 36
- Joined: Mon Jan 23, 2012 11:14 pm
- Location: Lancs, UK
Re: Pointer to pointer array of scene nodes
+1 to polylux .
Re: Pointer to pointer array of scene nodes
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.
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.