c++ - 为什么我会收到此错误:CSE 类没有名为 EnterRN 和 EnterName 的成员?
问题描述
#include <iostream>
using namespace std;
class CSE
{
private:
char Name;
double Roll;
public:
void getN(char N, double RN)
{
Name = N;
Roll = RN;
}
};
char EnterName()
{
cout << "Enter the name of the student" << ;
}
char EnterRN()
{
cout << "enter the rn" << ;
};
int main()
{
CSE nnn;
nnn.getN(N, RN);
cout << "enter the name" << nnn.EnterName << endl;
cout << "enter the roll" << nnn.EnterRN << endl;
return 0;
}
为了正确实现我的代码,我应该在这里更正什么?我只想将姓名和卷号保密,然后再公开。我还想输入用户的姓名和卷号,然后显示。
解决方案
您正在定义(免费)函数,而不是声明和定义方法:
class CSE {
...
public:
char EnterRN();
};
char CSE::EnterRN() {
...
}
如果你想内联,那么类的结束 } 需要在这些函数之后。
推荐阅读
- azure-data-factory - 在实际源中找不到源数据集中定义的列
- sql-server-2012 - I can't find the option to exclude constraints when using SQL Server Management Studio script generation
- playframework - How does a HTTP redirect work in the Play Framework?
- php - 如何将 preg_replace 转换为 php7 的 preg_replace_callback
- javascript - 当我们单击图像缩略图时,我们如何显示带有图片的文本?
- hadoop - HIVE 中的 ALTER TABLE 命令中的 CONCATENATE 是如何工作的
- ios - Swift3 - 二元运算符“==”不能应用于“AnyObject?”类型的操作数 和“文件属性类型”
- powershell - 使用 CSV 附加文件名
- scala - 带有 Graph DSL 的 Websocket
- cygwin - 带有 Cygwin 的 Conda:已创建环境,但未找到位置且激活后无法使用