求大神指教!这个程序哪里错了????????
#include<iostream>using namespace std;
class student
{
private:
int age;
char * name;
public:
student(int m,char * n);
student();
~student();
void setmember(int m,char * n);
int Getage();
char * Getname();
};
student::student(int m,char * n)
{
age=m;
name=new char[strlen(n)+1];
strcpy(name,n);
}
student::~student()
{
delete []name;
}
student::student()
{
age=0;
name=new char[10];
name="未给定初值";
}
void student::setmember(int m,char * n)
{
age=m;
name=n;
}
int student::Getage()
{
return age;
}
char * student::Getname()
{
return name;
}
int main()
{
student S[3]={student(25,"肖某"),student(23,"何某")};
for(int i=0;i<3;i++)
{
cout<<S[i].Getname()<<" "<<S[i].Getage()<<'\n';
}
return 0;
}
[ 本帖最后由 IT男year 于 2013-10-16 12:44 编辑 ]