Originally Posted by
Dirich
In a certain .hpp of mine, I would like to define a list of two alternating kind of structures:
Code:
struct A
{
/* TONS of stuff */
B* Next;
B* Previous;
};
struct B
{
/* very few stuff */
A* Next;
A* Previous;
};
The problem, the way I wrote this code, is that the compiler has no idea of what B is when it finds it while reading the definition of struct A. With functions the problem is solved by pre-declaring them at the beginning of the file or by declaring the header.
How do I do it (without putting everything in a single structure so that the problem is avoided altogheter)?
I think another way of solving this is with "forward declaration" of the struct/class. Warning I didn't actually try to compile the following code:
Code:
struct B; //forward declare the struct
struct A
{
/* TONS of stuff */
B* Next;
B* Previous;
};
struct B
{
/* very few stuff */
A* Next;
A* Previous;
};
Bookmarks