#includeusing namespace std; class Student { public: Student(int no,const char* r, int a); void show(); ~Student(); private: int number; char* name; int age; static int count; }; int Student::count = 0; Student::Student(int no,const char *r,int a)//为毛不加const就编译不了 { number = no; name = new char[strlen(r) + 1]; strcpy_s(name, strlen(r) + 1, r); age = a; count = count + 1; cout << "构造学生" << count << endl; } void Student::show() { cout << number << "t" << name << "t" << age << endl; } Student::~Student() { delete name; cout << "析构学生" << count << endl; count = count - 1; } int main() { int sum = 0; Student s[3] = { Student(202001,"张三", 21), Student(202002,"李四", 22), Student(202003,"王五", 23) }; for (int i = 0; i < 3; i++) { s[i].show(); } return 0; }



