I've asked a question once, but I didn't explain it last time, let me talk about it this time. Masters help to see how to solve.
testA.h:
#if! defined (_a_)
#define _a_
#include "testB.h"
class A {
public:
B b;
public:
aMethod ();
};
#endif
testA.cpp:
#include "testA.h"
A :: aMethod () {
}
testB.h
#if! defined (_b_)
#define _b_
// # include "testA.h" <-This Include is not easy to use
class A;
class B {
public:
A * a;
public:
setA (A * a);
bMethod ();
};
#endif
testB.cpp
#include "testB.h"
B :: setA (A * a) {
this-> a = a;
}
B :: bMethod () {
a-> aMethod ();
}
Compiling class A is fine, compiling class B has errors:
testB.cpp
testB.cpp (6): error C2027: Undefined type "A" was used
d:\dxsdk\Extras\DirectShow\Samples\C ++\DirectShow\course_client2\destop capture filter\testB.h (4): See the statement of "A"
testB.cpp (6): error C2227: The left side of "-> aMethod" must point to class / structure / union
There is only a pointer of class A in class B, then there is a forward declaration of class A when class B is defined,
However, class A uses class B as a member, so when defining class A, you must see the complete definition of class B.