#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() {
...
}
如果你想内联,那么类的闭包}必须在这些函数之后。