麻烦大家帮我看下这个程序怎么改
#include<iostream>#include<string>
using namespace std;
class Person
{
public:
Person(char* n,int age,char *sex)
{
strcpy(N,n);Age=age;strcpy(Sex,sex);
}
~Person(){}
char *Getname(){return N;}
int GetAge(){return Age;}
char *GetSex(){return Sex;}
private:
char *N;
int Age;
char *Sex;
};
class Student:public Person
{
public:
Student(char *n,int age,char *sex,double score): Person(n, age, sex),Score(score)
{}//Score=score;}
~Student(){}
float GetScore(){return Score;}
private:
double Score;
};
void main()
{
Student y("zhangsan",58,"男",92.1);
cout<<"Student的姓名为:"<<y.Getname()<<"年龄为:"<<y.GetAge()<<"性别为:"<<y.GetSex()<<"分数为:"<<y.GetScore()<<endl;
}
编译没错误,运行的时候就出现错误了!!
刚学c++的继承与派生,结果同学说要我帮他改,我看了就觉得是构造函数里面指针可能错了,不过不知道怎么改,也不知道对不对,大家帮下忙,谢谢