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.
Abraxas)
Posts: 227
Joined: Sun Oct 18, 2009 7:24 am

Re: Pointer to pointer array of scene nodes

Post by Abraxas) »

robmar I'm not sure why you don't just pass the name of the first member of the group as the pointer to the array.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

that´s of course what I did!!

Read my posts please everyone!!!

VS C++ DOES NOT ALLOW passing ptrs to ptr arrays of neither void nor abstract classes!!!!!

By just changing from an array of ILightSceneNode pointers to an array of vector3fd pointers, everything compiles.

But MY AIM HERE is to have an array of ILightSceneNode pointers, and pass a ptr of it!!! Which VC++ does not allow!!!

That is unless someone else can prove otherwise by actually doing it, compiling it, not just saying it!
Last edited by robmar on Tue Jan 08, 2013 5:39 pm, edited 1 time in total.
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: VS C++ DOES NOT ALLOW passing ptrs to ptr arrays of neither void nor abstract classes!!!!!
Image
Working on game: Marrbles (Currently stopped).
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

:lol:
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 »

I must admit I just tried it for a few minutes and also couldn't figure out how to pass it correct. Polylux definition is correct for beeing an array full of pointers, so much is certain. Passing it by value would also be simple. But passing a pointer to that with the restriction of the size in the constant correctly... would need more time to figure that out it seems :-)

Maybe use some typedef - makes things often easier.
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 »

Its a bit of a head-twister for sure.... and where is the logic in not allowing this:-

void *p1[8]; // Array of void pointers

void (*p2)[8]; // Single pointer to an array of void pointers

p2 = p1; // Not allowed, ptr to array of voids not legal!

The parenthesis is important to stop the 2nd declaration becoming another array of pointers

But this is legal:-

int *p1[8]; Array of int pointers

int (*p2)[8]; // Single pointer to an array of int pointers

p2 = p1; // Allowed, ptr to array of ints IS legal!
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 »

void (*p2)[8]; is a pointer to an array of void - not to an array of void*.
Same in your second example - which also doesn't compile here by the way (gcc).

edit: And yes - it's a horrible syntax. Same problem in language design as everywhere in programming - if you don't get it right on the first time then you're stuck with it for eternity :-)

There are some rules how to read those declarations which you can find browsing around al little (something about going left-right-left-right all the time, but I must also look it up if I have such a structure once every few years).
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 »

I knew I´d probably screw that up somewhere! :)

So...

void *(*p2)[8] // Pointer to an array of void pointers...

This is a pointer, type void, to an array of pointers...

or should that be:-

void (*p2)(*)[8] // Pointer to an array of void pointers

my mind goes blank sorta quickly with this syntax!
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Pointer to pointer array of scene nodes

Post by hendu »

Eh, chill with the arrays and just go full-pointers ;)

void **p1; // pointer to an array of void *
void ***p2; // pointer to a pointer to an array of void *
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Pointer to pointer array of scene nodes

Post by robmar »

That sounds soooo easy! Did you try it by passing a ptr to an array of voids or even ILightSceneNode ptrs? ... maybe you should try it!

void *pLights[8];
void ***...
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Pointer to pointer array of scene nodes

Post by serengeor »

what about what I posted before:

Code: Select all

#include <iostream>
 
class Abstract
{
public:
  virtual void pureVirt() = 0;
};
 
void func(Abstract ** b);
 
int main()
{
    Abstract * array[99];
    
    func(array);
    
    if(array[0]==NULL)
        std::cout << "is NULL\n";
    
    return 0;
}
 
void func(Abstract ** b)
{
    b[0]=NULL;
}
:roll:
Working on game: Marrbles (Currently stopped).
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 »

serengeor: Yeah, passing that way is still easy. But what I couldn't figure out is the additional size restriction - so the function can only pass a pointer to an array of a certain size.
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 »

Did you try to compile it?

The only person so far who did a real test, CuteAlien, also reported that it produced compiler errors.
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 »

Uhm - I didn't test this one - that should work (on first view - didn't compile this). It's just passing a pointer to an array of pointers of undefined size. Which means you either have to set the last to 0 or pass the lenght or you won't know how many are in there. The difficulty I'm having is the size-constant you are using...
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 »

what size constant? I think this all seems so simple, that is until you try it! Then you get Error! Void and abstract class ptr to ptrs not legal...
Post Reply