编译器错误 C4430:缺少类型说明符 - 假定为 int [重复]

问题描述 投票:0回答:1

我有这个错误:

“错误 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.
};
c++ compiler-errors include circular-dependency
1个回答
31
投票

这是一个“循环依赖”问题。为了声明指向某个类的指针,不需要该类的定义;即该类型不必是“完整类型”。 所以你不需要在 A.h 中包含 B.h

前向声明
就足够了。如:

//B.h class A; // change the include of A.h to forward declaration class B { A* a; };

© www.soinside.com 2019 - 2024. All rights reserved.