Original Post
These are the files: a.h:
#ifndef _A_
#define _A_
#include "b.h"
class A
{
public:
B b;
void test();
};
#endif
b.h:
#ifndef _B_
#define _B_
class A;
class B
{
public:
A* parent;
void test();
};
#endif
b.cpp:
#include "b.h"
void B::test()
{
parent->test();
}
main.cpp:
#include <stdio.h>
#include "a.h"
void A::test()
{
printf("Test.\n");
}
int main()
{
return 0;
}
I try to compile, but I get errors:
g++ test.cpp b.cpp
b.cpp: In member function ‘void B::test()’:
b.cpp:5: error: invalid use of incomplete type ‘struct A’
b.h:4: error: forward declaration of ‘struct A’
Notice that I do not get any errors if I comment a part of b.cpp:
void B::test()
{
//parent->test();
}
What causes the errors?