在一个类中怎么在成员函数中设置成员变量的数值
怎么在成员函数SetInfor中设置成员变量的数值class CStudent
{
char name;
char sex;
int grade;
int classe;
public:
CStudent(){}
int Setlnfor();
int Showlnfor();
};
int CStudent::Setlbnfor()
{
CStudent::name = yuan;
CStudent::sex = nv;
CStudent::classe= 5;
return 0;
}
int CStudent::Showlnfor()
{
std::cout<<CStudent.name<<std::endl<<CStudent.sex<<std::endl;<<CStudent::classe<<std::endl;
}
int main()
{
CStudent c1(yuan,nv,5);
c1.Showlnfor();
return 0;
}
=====运行开始======
:14: 错误:程序中有游离的‘\357’
:14: 错误:程序中有游离的‘\274’
:14: 错误:程序中有游离的‘\233’
:15: 错误:程序中有游离的‘\357’
:15: 错误:程序中有游离的‘\274’
:15: 错误:程序中有游离的‘\233’
:12: 错误:成员函数‘int CStudent::Setlbnfor()’未在类‘CStudent’中声明
: In member function ‘int CStudent::Showlnfor()’:
:21: 错误:‘cout’不是‘std’的成员
:21: 错误:expected primary-expression before ‘.’ token
:21: 错误:‘endl’不是‘std’的成员
:21: 错误:expected primary-expression before ‘.’ token
:21: 错误:‘endl’不是‘std’的成员
:21: 错误:expected primary-expression before ‘<<’ token
:21: 错误:‘endl’不是‘std’的成员
: In function ‘int main()’:
:25: 错误:‘yuan’在此作用域中尚未声明
:25: 错误:‘nv’在此作用域中尚未声明
=====运行结束======