In A.hpp file I have a structure, which has a pointer of B class
struct state
{
B *b;
};
In A.hpp file, I added a forward declaration and I included B.hpp file in A.cpp file
//A.hpp
class B
In B.hpp file, a function uses the state, which declared in A.hpp as an argument on the function.
bool function_in_b(state *s)
I also added a forward declaration of A in B.hpp file and I added the header file of A, A.hpp in B.cpp file.
//B.hpp
class A
All header files have a header guard. If I try to compile, it won’t find ‘state’ declared in A.hpp. Thus, it won’t find the matching function and complains the candidates are
bool function_in_b(int *)
How do I fix this problem?
In
B.hpp, you say you forward-declaredA, but notstate– so when it first seesfunction_in_b(state *s)it doesn’t know whatstateis. By the time you includeA.hppinB.cppit’s too late. You need to forward declarestateinB.hpp, i.e.