两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
来源:互联网 发布:mac os 磁盘分区 编辑:程序博客网 时间:2024/05/17 02:25
编译错误一: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;
};
参照: http://www.allegro.cc/forums/thread/586909
同样紧跟上面的例子,通过问题一的办法,第一个错误已经消失,但是马上第二个错误就出现了!还是同一个位置。
这个错误的意思,就是说class B中的XX域的类型不够完整,为什么呢?明明class A后面已经定义好了啊。其实原因还是和前面一样,在class B定义之前,我们也只是对class A进行了声明而并没有进行具体的定义,所以解决该错误的方法是:
将class B定义中的A域改用指针就行了。改正后代码为:
class A;
class B{
public:
B(){}
~B(){}
private:
A *a;
};
class A{
public:
A(){}
~A(){}
private:
int a;
};
这样,这段简单的代码才能没有错误的通过编译。
- 两个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
- 编译错误--------: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
- C++报错集合:XX does not name a type;field `XX' has incomplete type
- has not been declared和does not name a 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
- 常用的数据标准化方法
- Apache组件commons的DbUtils的用法实例
- 单词查找树
- UML解惑---UML类图符号 各种关系说明以及举例
- Unix系统安全——绿盟科技
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- 【js学习笔记-014】-- 转义字符
- HDU2199
- JSP中的全局变量和局部变量
- HDU2899
- 解决ADB server didn't ACK问题
- zoj 2277 (数论)
- Accepted Necklace 2660
- 机电类特种设备(起重、电梯、厂车)报告管理软件