Cross-references in headers
Can somebody please explain me the correct way to make correct inclusions when class A needs B and class B needs A (two-directional link)?
Here is an example of the source code:
The GCC 2.95 gives me an error - class B is undefined in class A.
Here is an example of the source code:
#ifndef coolclassa
#define coolclassa
#include "B.h"
class Aclass
{
public:
Bclass *buddy;
Aclass( Bclass *newB ) : buddy( newB )
{}
};
#endif#ifndef coolclassb
#define coolclassb
#include "A.h"
class Bclass
{
public:
Aclass *buddy;
Bclass( Aclass *newA ) : buddy( newA )
{}
};
#endif#include "A.h"
#include "B.h"
int main()
{}The GCC 2.95 gives me an error - class B is undefined in class A.
