There are many references about it online but I like this one:
http://stackoverflow.com/questions/625799/resolve-header-include-circular-dependencies
The way to think about this is to "think like a compiler".
Imagine you are writing a compiler. And you see code like this.
// file: A.h
class A {
B _b;
};
// file: B.h
class B {
A _a;
};
// file main.cc
#include "A.h"
#include "B.h"
int main(...) {
A a;
}
When you are compiling the .cc file (remember that the .cc and not the .h is the unit of compilation), you need to allocate space for object
A
. So, well, how much space then? Enough to store B
! What's the size of B
then? Enough to store A
! Oops.
......you can read on.
ref:
http://stackoverflow.com/questions/3961103/error-does-not-name-a-type (inspired by this)
http://stackoverflow.com/questions/2133250/does-not-name-a-type-error
http://stackoverflow.com/questions/8470822/error-x-does-not-name-a-type
http://stackoverflow.com/questions/625799/resolve-header-include-circular-dependencies
No comments:
Post a Comment