c++相关查询中的类原型
class prototype in c++ related query
如果我想在main()之后声明,如何在c++中为类提供原型?我写了以下代码片段。我参考了cplusplus.com上的材料,我试着在谷歌上搜索它,但找不到任何有用的东西。我错误地在main下面声明了这个类,但后来我意识到我没有给出它的原型,因此我的程序无法运行。
#include<iostream.h>
#include<conio.h>
void main()
{
student s;
s.show();
getch();
}
class student
{
int age;
public:
void show();
};
void student::show()
{
age = 5;
cout << age;
}
你不能。如果编写student s;
,则student
必须是完整类型。因此,远期申报是不够的。
显而易见的解决方案是在一个名为student.h
和#include
的文件中编写类声明,该文件位于定义main()
的文件的顶部。
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 函数向量_指针有不同的原型,我可以构建一个吗
- 查询SQLite数据库中的日期
- 如何在ArangoDb AQL查询中指定数据库
- 功能原型的目的
- Qt SQLite没有查询或参数计数不匹配
- getline() 的原型/库是什么;
- 如何使用c++在VS 2019上运行SQL查询
- 从返回的顶点缓冲区查询顶点结构
- 具有enable_if外部类原型的模板类构造函数定义
- 函数如何通知用户它基于函数原型抛出异常?
- 以非特权用户身份查询 NTFS 特殊文件的元数据?
- C/C++ - 查询平台相关的换行符(用于内存映射文件)
- 在C++中包含原型文件的正确方法是什么?
- 在函数中拥有函数原型的目的是什么?
- 什么..(省略号)作为函数原型中唯一的函数参数,C++?
- 是否可以使用 libclang python 解析 cpp 文件中没有标头的函数原型
- 查询 NFS 上的提升进程间::file_lock
- Qt JSON – 从子项查询
- c++相关查询中的类原型