编译错误 --- does not name a type和field `XX' has incomplete type
来源:互联网 发布:淘宝货到付款流程 编辑:程序博客网 时间:2024/06/05 15:49
编译错误一:XX does not name a type
编译错误二:field `XX' has incomplete type
编译错误一:XX does not name a type, 中文意思为“XX没有命名一个类型“
拿个例子来讲,如果两个类定义如下:
class B{public:B(){}~B(){}private:A a;};class A{public:A(){}~A(){}private:int a;};
编译成则将报一个error:"A does not name a type"
报错的位置为红色那一行。
即使clase A和class B分别在两个文件定义,并且在定义B的文件头中#include了class A的头文件也同样会报这个错(这是因为编译和链接之间的先后关系造成的)。
解决该错误的办法:
在class B定义声明之前先声明一下class A, 如下:
class A;class B{public:B(){}~B(){}private:A a;};class A{public:A(){}~A(){}private:int a;};
编译错误二:field `XX' has incomplete type
同样紧跟上面的例子,通过问题一的办法,第一个错误已经消失,但是马上第二个错误就出现了!还是同一个位置。
这个错误的意思,就是说class B中的XX域的类型不够完整,为什么呢?明明class A后面已经定义好了啊。其实原因还是和前面一样,在class B定义之前,我们也只是对class A进行了声明而并没有进行具体的定义,所以解决该错误的方法是:
将class B定义中的A域改用指针就行了。改正后代码为:
class A;class B{public:B(){}~B(){}private:A *a;};
这样,这段简单的代码才能没有错误的通过编译。
link: http://blog.csdn.net/guogaofeng1219/article/details/5808561
0 0
- 编译错误--------:XX does not name a type和field `XX' has incomplete type
- 编译错误 --- does not name a type和field `XX' has incomplete type
- 编译错误 --- does not name a type和field `XX' has incomplete type
- 编译错误 --- does not name a type和field `XX' has incomplete type
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type 编译错误一:XX does not name a type 编
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- 两个C++编译异常及解决方法-does not name a type和field `XX' has incomplete type
- C++报错集合:XX does not name a type;field `XX' has incomplete type
- 编译CEGUI时field has incomplete type Ogre::TexturePtr错误
- 编译CEGUI时field has incomplete type Ogre::TexturePtr错误
- ptrdiff_t does not name a type造成编译错误
- ndk编译错误:error: 'override' does not name a type
- field has incomplete type
- 1009 二叉搜索树
- 用VMware搭建Ubuntu虚拟机
- appearanceWhenContainedIn
- iPhone学习之路 TableView实现动态加载图片
- hibernate配置文件简介,以及主键生成策略
- 编译错误 --- does not name a type和field `XX' has incomplete type
- 对称密钥与非对称密钥
- 读取iOS设备中应用的数据
- Servlet基础 及详细介绍(附带代码)
- Note Pad++ 和 Srt 两个工具的两点小应用
- Grizzly:Java NIO框架
- TCP实现过程详解
- opencv特征检测之角点检测
- 关于 myqsl的字符存储问题