Originally Posted by
mikro
the pointer points to an instance of a class which i had to forward declarate.
If you have only forward declaration, then you can't invoke any method, constructor or destructor of that class. Compiler simply doesn't know if they exist. You must add proper #include directive.
Originally Posted by
mikro
So both classes need to use each others methods, i either get a DoD or Problems like the above ;(
You can solve it with forward declarations, like this:
// a.h
class B; // forward declaration only, so you can't use B instances here
class A
{
...
void someMethod( const B& b ); // this will work
void someOtherMethod( B* b ); // this is also ok
...
private:
B *_b; // note that you can use only a pointer here, since you can't include class definition
};
//-------------------------------------------------------------------
// b.h
class A;
class B
{
...
private:
A *_a;
};
//-------------------------------------------------------------------
// a.cpp
#include "a.h"
#include "b.h"
vouid A::someMethod( const B& b )
{
// you can use B here
}
// a.h
class B; // forward declaration only, so you can't use B instances here
class A
{
...
void someMethod( const B& b ); // this will work
void someOtherMethod( B* b ); // this is also ok
...
private:
B *_b; // note that you can use only a pointer here, since you can't include class definition
};
//-------------------------------------------------------------------
// b.h
class A;
class B
{
...
private:
A *_a;
};
//-------------------------------------------------------------------
// a.cpp
#include "a.h"
#include "b.h"
vouid A::someMethod( const B& b )
{
// you can use B here
}
To copy to clipboard, switch view to plain text mode
Bookmarks