Circular dependence with direct declaration

In the A.hpp file, I have a structure that has a pointer to class B

struct state
{
    B  *b;
};

In the A.hpp file, I added the ad ahead, and I included the B.hpp file in the A.cpp file

//A.hpp
class B

In a B.hpp file, a function uses the state that A.hpp declared as an argument to the function.

bool function_in_b(state *s)

I also added the declaration of A in the B.hpp file and added the header file A, A.hpp in the B.cpp file.

//B.hpp
class A

All header files have header protection. If I try to compile, it will not find the "state" declared in A.hpp. Thus, he will not find a matching function and complains that the candidates

bool function_in_b(int *) 

How to fix this problem?

Thanks in advance

+3
source share
2 answers

B.hpp , A, state - , function_in_b(state *s), , state. , A.hpp B.cpp, . declare state B.hpp, ..

struct state;

bool function_in_b(state *s);
+2

B.hpp function_in_b(state *) state:

struct state;
+1

All Articles