#include
#include
#include
const char * null="";
class Student
{ //see declaration of 'Student'
public:
Student();
Student(char * pname, char sexl, char * pid,int a,float s);
void getid(char * pid);
void getname(char * pname);
void getsex(char sexl) {sex=sexl;}
void getage(int a) {age=a;}
void getscore(float s) {score=s;}
void display();
~Student();
private:
char * name;
char sex;
char * id;
int age;
float score;
};
Student::Student()
{
id = new char[10];
strcpy(id,"00000000");
name = new char[20];
strcpy(name,null);
sex=' ';
age=0;
score = 0;
}
Student::Student(char * pname,char sexl,char * pid,int a,float s)
{ //error C2511: 'Student::Student' : overloaded member function 'void (char *,char,char *,int,float)' not found in 'Student'
id = new char[strlen(pid)+1];
strcpy(id,pid);
name = new char[strlen(pname)+1];
strcpy(name,pname);
sex =sexl;
age =a;
score = s;
}
void Student::getid(char * pid)
{
delete[] id;
id = new char[strlen(pid)+1];
strcpy(id,pid);
}
void Student::getname(char * pname)
{
delete[] name;
name = new char[strlen(pname)+1];
strcpy(name,pname);
}
void Student::display()
{
cout<<"name:"<
Student::~Student()
{
delete[] name;
delete[] id;
}
void main()
{
Student s1;
s1.display();
s1.getid("03060101");
s1.getname("Wang Fei");
s1.getsex('F');
s1.getage(19);
s1.getscore(95);
s1.display();
Student s2("Chen Wei",'M',"036060102",18,98); //error C2661: 'Student::Student' : no overloaded function takes 5 parameters
s2.display();
getch();
}
重载函数的时候少写了参数将Student(char * pname,char * pid,int a,float s); 改成Student(char * pname,char sexl,char * pid,int a,float s)