关于不完整类型:
来源:互联网 发布:paparecipeq正品软件 编辑:程序博客网 时间:2024/04/29 22:32
关于不完整类型:
我们可以只是声明而不真正地定义一个类,比如
class Screen;
这样做的含义:
“This declaration, sometimes referred to as a forward declaration , introduces the name Screen into the program and indicates that Screen refers to a class type. After a declaration and before a definition is seen, the type Screen is an incompete type it's known that Screen is a type but not known what members that type contains.”
这句很重要:
“An incomplete type may be used to define only pointers or references to the type or to declare (but not define) functions that use the type as a paremeter or return type.”
这是很容易犯的错误,而且如果不知道这个知识,当面临error的时候也不知所措。一个不完整类型不可以用来直接定义对象,但可以用来定义一个指向该不完整类型的指针或者一个与该类型绑定的引用,而且还可以用来声明一个函数,这个函数使用了这个不完整类型作为形参或者返回值。记住,这里指的是声明,也就直接加分号,不可以有定义。
class LinkScreen {
Screen window;
LinkScreen *next; //到这里的时候,该类并没完整,但这个时候可以定义一个指向该类的指针,与上面所述一致
LinkScreen *prev; //同上
}; //到这里类的定义才算完整
- 关于不完整类型:
- C与C++关于不完整类型的说明
- 不完整类型incomplete type
- 关于“不允许指针指向不完整的类类型”问题分析
- 关于“不允许指针指向不完整的类类型”问题分析
- 不完整结构类型的定义
- c++避免delete不完整类型 --checked_delete
- [错误]不允许使用不完整的类型
- 柔性数组_不完整类型
- mybatis 参数类型--不完整//与特殊符号# | $
- 关于继承的不完整总结
- 关于TCP协议收到数据不完整
- C语言的不完整类型与封装
- C语言的不完整类型和前置声明
- C++不允许使用指向不完整类型的指针
- C++错误:不允许使用不完整的类型
- C语言的不完整类型和前置声明
- “不允许指针指向不完整的类类型”问题分析
- Visual Studio 2010 快捷键
- sas/iml矩阵算术
- 智力题目-01分苹果
- c++虚函数表详解(七)
- Win7开机密码破解
- 关于不完整类型:
- 文件下载程序--AfxParseURL
- objective-C: NSString应当用initWithFormat? 还是 stringWithFormat?
- 生活小贴士
- MTK进阶计划
- 柳传志:你得知道自个儿是谁
- MYSQL学习资料整理(自制软件+基础资料)
- 使用cmake构建复杂源码
- epoll精髓