use*_*201 10 c++ compiler-errors circular-dependency include
我有这个错误:
"错误C4430:缺少类型说明符 - 假定为int.注意:C++不支持default-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.
};
Run Code Online (Sandbox Code Playgroud)
son*_*yao 20
这是一个循环依赖问题.为了声明指向某个类的指针,不需要该类的定义; 即类型不必是完整类型.所以你并不需要包括A.h在B.h,向前声明是不够的.如:
//B.h
class A; // change the include of A.h to forward declaration
class B {
A* a;
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67173 次 |
| 最近记录: |