编译器错误C4430:缺少类型说明符 - int [英] Compiler error C4430: missing type specifier - int assumed

查看:221
本文介绍了编译器错误C4430:缺少类型说明符 - int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个错误:

错误C4430:缺少类型说明符 - int假设注意:C ++不支持default-int

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


推荐答案

这是循环依赖问题。特别是,要声明一个指向某个类的指针,不需要类的实际定义。
因此,您不需要在 Bh 中包含 Ah 前进声明就够了。如:

This is a circular dependency issue. In particular, to declare a pointer to some class, the actual definition of a class is not needed. 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;
};

这篇关于编译器错误C4430:缺少类型说明符 - int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆