- 有以下类定义,写出该类的构造函数,析构函数,拷贝构造函数,要求,所有类对象的空间都是用new动态申请。
class Stu { string name; int age; int score; int *high; };
#include <iostream> using namespace std; class Stu { string name; int age; int score; int *high; public: Stu() { cout<<"无参构造"<<endl; } Stu(string n,int a,int s,int *h)name(n),age(a),score(s),high(h) { cout<<"有参构造"<<endl; } ~Stu() { cout<<"析构函数"<<endl; } Stu(Stu &s):name(s.name), age(s.age), score(s.score) { cout<<"拷贝构造函数"<<endl; this->high=new int(*(s.high)); } }; int main() { return 0; }