How should I resolve the following type of circular dependency?
//A.hpp
#include "B.hpp"
struct A {
B b;
int foo();
};
//A.cpp
#include "A.hpp"
int A::foo{
b.fi(*this);
}
//B.hpp
struct A;
struct B {
int fi(const A &a);
};
//B.cpp
#include "B.hpp"
int B::fi(const A &a){
if(a.something())
something_else();
}
Forward declare A
in B.hpp
as you have,, then include A.hpp
in B.cpp
. That's what forward declarations are for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With