我有这个错误:
“错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持默认 int”
使用此代码示例:
//A.h #include "B.h" class A{ B* b; .. }; //B.h #include "A.h" class B{ A* a; // error error C4430: missing type specifier - int assumed. };
这是一个“循环依赖”问题。为了声明指向某个类的指针,不需要该类的定义;即该类型不必是“完整类型”。 所以你不需要在 A.h 中包含 B.h,
A.h
B.h
前向声明
//B.h class A; // change the include of A.h to forward declaration class B { A* a; };