#include
using 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 << "构造学生------>" << number << "t" << name << "t" << age << endl;
cout << "学生数:" << count << endl << endl;
}
void Student::show()
{
cout << number << "t" << name << "t" << age << endl;
}
Student::~Student()
{
count = count - 1;
cout << "析构学生------>" <";
p[i]->show();
delete p[i];//程序结束前使用delete释放由new分配的内存
}
return 0;
}