Compiler error C4430: missing type specifier - int assumed [duplicate]

谁说我不能喝 提交于 2019-12-09 05:26:12

问题


I have this error:

"error C4430: missing type specifier - int assumed. Note: C++ does not support 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.
};

回答1:


This is a circular dependency issue. 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 declaration is enough. Such as:

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


来源:https://stackoverflow.com/questions/23283080/compiler-error-c4430-missing-type-specifier-int-assumed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!