I know circular dependency can be resolved by forward declaration and pointer like this:
A.h
class B;
class A{
public:
void update(B* b);
void test(){}
};
A.cpp
#include "A.h"
#include "B.h"
void A::update(B* b){
b->test();
}
B.h
class A;
class B{
public:
void update(A* a);
void test(){}
};
B.cpp
#include "B.h"
#include "A.h"
void B::update(A* a){
a->test();
}
so that the code above can compile with containing each other,but the problem is, why can it be said as "resolving circular dependency"? I was not satisfying that "B" still exists in source code of A and "A" still exists in source code of B. At least I think it should change the design pattern so that no class can contain each other,e.g,using a parent class to hold A and B.:
Parent.h
class A;
class B;
class Parent{
void update(A* a,B* b);
};
Parent.cpp
void Parent::update(A* a,B* b){
a->test();
b->test();
}
why using forward declaration and pointer can said to be "resolve circular dependency" even the source code still contains each other?