首页 > 解决方案 > 为什么我会收到此错误: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;
}

为了正确实现我的代码,我应该在这里更正什么?我只想将姓名和卷号保密,然后再公开。我还想输入用户的姓名和卷号,然后显示。

标签: c++

解决方案


您正在定义(免费)函数,而不是声明和定义方法:

class CSE {
   ...
   public:
      char EnterRN();
};

char CSE::EnterRN() {
  ...
}

如果你想内联,那么类的结束 } 需要在这些函数之后。


推荐阅读