Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

cryo75

Structure pointing to self??

This topic is 5490 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the following structure:
	typedef struct tagQuad {
		D3DXVECTOR3 vCoords[4];
		QUADNODE*   qChildren[4];
	} QUADNODE;
I get an error on QUADNODE*: missing storage-class bla bla... Basically I want that the struct points to itself. This is for a quadtree. How can I do it?? Thanks, Ivan

Share this post


Link to post
Share on other sites
Advertisement
You are trying to use an instance of tagQuad called QUADNODE as your children''s type.

-Nik

Share this post


Link to post
Share on other sites
I changed QUADNODE* to tagQuad* and it compiled without grumbling.

What''s the difference though??

Share this post


Link to post
Share on other sites
it only works like this:


typedef struct tagQuad {
D3DXVECTOR3 vCoords[4];
tagQuad* qChildren[4];
} QUADNODE;

Share this post


Link to post
Share on other sites
try forward declaring it...


struct QUADNODE;
typedef struct tagQuad
{
D3DXVECTOR3 vCoords[4];
QUADNODE* qChildren[4];
} QUADNODE;


Edit: This won't work, but kept it to show a bad example! Whee!


[edited by - stonicus on October 7, 2003 10:55:21 AM]

Share this post


Link to post
Share on other sites
standard way of doing this is:

typedef struct tagQuad QUADNODE, *PQUADNODE;

struct tagQuad {
D3DXVECTOR3 vCoords[4];
QUADNODE* qChildren[4];
};

this compiles on VS.NET 2003.

ld

Share this post


Link to post
Share on other sites
That''s standardish for plain C, in C++ you don''t need to do any of that silly typedef stuff.

Here are the ways of doing it


//Old C method

typedef struct tagQUADNODE {
D3DXVECTOR3 vCoords[4];
tagQUADNODE* qChildren[4];
} QUADNODE;

//C++ method

struct QUADNODE {
D3DXVECTOR3 vCoords[4];
QUADNODE* qChildren[4];
};

Share this post


Link to post
Share on other sites
Hey AikonIV, I tried the c++ method and it does not compile. the c method works though. Strange.

Share this post


Link to post
Share on other sites
quote:
Original post by cryo75
Hey AikonIV, I tried the c++ method and it does not compile. the c method works though. Strange.


The first one works, because the struct doesn''t rely on the typedef statement during the structure. You can''t reference the name of the typedef until after the closing brace of the struct declaration, because it simply doesn''t exist at that point.


typedef struct tagQUADNODE {
D3DXVECTOR3 vCoords[4];
tagQUADNODE* qChildren[4]; // QUADNODE doesn''t exist here.

} QUADNODE; // It exists here, though.



It''s like trying to reference something that isn''t complete yet. The typedef needs all the information from the struct''s declaration, in order to create the typedef itself. That means, that until it''s processed the declaration, the typedef isn''t created.

-hellz

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!