tags:

views:

117

answers:

3

Hello. A bit of a noob question: I need classes A and B such that A has a B* member and B has an A* member.

When compiling I get "error: ISO C++ forbids declaration of ‘B’ with no type". How can I get around this?

+13  A: 

Forward declare B (or A )

class B; //forward declaration of B

class A
{
   B *b;
};

class B
{
   A *a;
};
Prasoon Saurav
+6  A: 

Forward declare one of class a or b.

class b; //forward declaration

class a{
//class a stuff
b* ptrtoB;

};


class b{
//class b stuff
a* ptrtoA;

};
shuttle87
+2  A: 

You can also inline forward declare one of the classes if nothing else is using it: class B* pMemberB; al la C style

Necrolis