为什么我得到这个错误:类CSE没有名为EnterRN和EnterName的成员?

  • 本文关键字:EnterRN 成员 EnterName CSE 错误 c++
  • 更新时间 :
  • 英文 :

#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() {
...
}

如果你想内联,那么类的闭包}必须在这些函数之后。

最新更新