Original Post
I am making a project with many classes, which have "relations" with each other. I make that by sample below(with guariands). That sample below is working, but if I include a.h instead b.h in main.cpp, then I get "error C2079: 'B::a' uses undefined class 'A'". I guess that happens because main.cpp calls A.h, when A.h calls B.h, and B.h doesn't include A.h anymore, because it's guarded(A_INC is defined), and class B don't know what class A is. Is this correct, and if yes, how to solve this? I would like to have ability to include those two files independently(not #include "b.h" and then #include "a.h", I know this works).
Sample code:
"main.cpp"
"a.h"
"b.h"
Sample code:
"main.cpp"
#include "b.h"
//#include "a.h" //this without upper include causes error
int main()
{
return 0;
}
"a.h"
#ifndef A_INC
#define A_INC
#include "b.h"
class B;
class A {
B *b;
};
#endif
"b.h"
#ifndef B_INC
#define B_INC
#include "a.h"
class A;
class B {
A a;
};
#endif