using namespace std;
class Student
{
public:
Student(char n,char na,char s,char g);
~Student();
void Print();
private:
char number,char*name,char sex,char grade;
};
Student::Student(char n,char*na,char s,char g)
{
number=n;
name=new char[20];
strcpy(name,na);
sex=s;
grade=g;
}
Student::~Student()
{
delete[] name;
cout<<"Student destructor"<<endl;
}
void Student::Print()
{
cout<<number<<endl;
cout<<name<<endl;
cout<<sex<<endl;
cout<<grade<<endl;
}
int main()
{
cout<<"输入学号:";
char n;
cin>>n;
cout<<"输入姓名:";
char*na;
cin>>na;
cout<<"输入性别(M 或 W):";
char s;
cin>>s;
cout<<"输入成绩:";
int g;
cin>>g;
Student Student(n,na,s,g);
Student.Print();
return 0;
}
5 个解决方案
#1
char -->char*
#2
Student(char n,char *na,char s,char g);
char number, *name, sex, grade;
char number, *name, sex, grade;
#3
函数申明和函数的第二个参数不一致
#4
private:
char number,char*name,char sex,char grade;哪有这么写的..
#5
char 一般要么用数组,要么用指针,char 只能存放一个字节,从你的代码来看,在这里肯定是不行的
#1
char -->char*
#2
Student(char n,char *na,char s,char g);
char number, *name, sex, grade;
char number, *name, sex, grade;
#3
函数申明和函数的第二个参数不一致
#4
private:
char number,char*name,char sex,char grade;哪有这么写的..
#5
char 一般要么用数组,要么用指针,char 只能存放一个字节,从你的代码来看,在这里肯定是不行的