1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include "student.h" #include <iostream> #include <string.h> using namespace std;
Student::Student() { } Student::Student(char *name, int age) { this->name = new char[strlen(name) + 1]; strcpy(this->name, name); this->age = age; }
Student::~Student() { cout << "析构函数执行了" << endl; delete[] name; name = NULL; }
void Student::show() const { cout << "name" << this->name << endl; cout << "age" << age << endl; }
int Student::getAge() { return this->age; }
|