Summary
I come across a compiling error, in which it says class A
was not declared. However, I actually include A.h
.
Details
After some research, I find out the bugs. In utils.h
, I want to use some static member varible in class A
and thus I include A.h
. However, since utils.h
acts as its name, I also include utils.h
in A.h
.
Then say in foo.cpp
, I include A.h
since I want to use the class A
. But A.h
includes utils.h
then utils.h
tries to include A.h
but the include guard blocks that, which causes that class A
was not declared in utils.h
.
As a solution, I make that utils.h
as independent as possible, and it does not include other user-defined classes (that’s what utils mean).