请问,这段代码错在哪
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class citizen
{
private:
char name[20];
char sex;
int age;
public:
citizen();
citizen(char name[], char sex, int age);
virtual void show();
~citizen()
{
ofstream myout;
myout.open("a.txt", ios::out | ios::app);
cout << "this is the first destruction function!" << endl;
myout << "this is the first destruction function!" << endl;
}
};
class student :public citizen
{
private:
char number[20];
char classname[20];
public:
student(char name[], char sex, int age, char number[], char classname[]) :citizen(name, sex, age)
{
strcpy_s(this->number, number);
strcpy_s(this->classname, classname);
}
void show();
~student()
{
ofstream myout;
myout.open("a.txt", ios::out | ios::app);
cout << "this is the second destruction function!" << endl;
myout << "this is the second destruction function!" << endl;
}
};
citizen::citizen(char name[], char sex, int age)
{
strcpy_s(this->name, name);
this->sex = sex;
this->age = age;
}
void citizen::show()
{
ofstream myout;
myout.open("a.txt", ios::out | ios::app);
cout << "姓名为:" << name << endl;
cout << "性别为:" << sex << endl;
cout << "年龄为:" << age << endl;
myout << "姓名为:" << name << endl;
myout << "性别为:" << sex << endl;
myout << "年龄为:" << age << endl;
}
void student::show()
{
ofstream myout;
myout.open("a.txt", ios::out | ios::app);
citizen::show();
cout << "学号为:" << number << endl;
cout << "班级为:" << classname << endl;
myout << "学号为:" << number << endl;
myout << "班级为:" << classname << endl;
}
int main()
{
ofstream myout;
myout.open("a.txt", ios::out | ios::app);
char name[20], number[20], classname[20];
char sex;
int age;
citizen *c;
cout << "请输入姓名,性别(男:m,女:f),年龄" << endl;
myout << "请输入姓名,性别(男:m,女:f),年龄" << endl;
cin >> name >> sex >> age;
myout << name << '\t' << sex << '\t' << age << endl;
c=&citizen(name, sex, age);
cout << "公民类的输出:" << endl;
myout << "公民类的输出:" << endl;
c->show();
cout << "请输入学号,班级" << endl;
myout << "请输入学号,班级" << endl;
cin >> number >> classname;
myout << number << '\t' << classname << endl;
c=&student(name, sex, age, number, classname);
cout << "大学生类的输出:" << endl;
myout << "大学生类的输出:" << endl;
c->show();
return 0;
}