C++ 编译器错误 C4430:缺少类型说明符 - 假定为 int
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23283080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compiler error C4430: missing type specifier - int assumed
提问by user3571201
I have this error:
我有这个错误:
"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int"
“错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int”
with this code example :
使用此代码示例:
//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.
};
回答by songyuanyao
This is a circular dependencyissue. For declaring a pointer to some class, the definition of the class is not needed; i.e. the type doesn't have to be a complete type.
So you don't need to include A.h
in B.h
, forward declarationis enough. Such as:
这是一个循环依赖问题。为了声明一个指向某个类的指针,不需要类的定义;即类型不必是完整类型。所以你不需要包含A.h
in B.h
,前向声明就足够了。如:
//B.h
class A; // change the include of A.h to forward declaration
class B {
A* a;
};