using namespace std;
class Stu
{
string name;
int age;
int score;
int *high;
public:
Stu()
{
cout<<"无参构造"<<endl;
}
Stu(string name,int age,int score,int *high):name(name),age(age),score(score),high(high)
{
cout <<"有参构造" <<endl;
}
~Stu()
{
delete high;
cout<<"析构函数"<<endl;
}
Stu (Stu &s):name(s.name),age(s.age),score(s.score)
{
cout<<"拷贝函数"<<endl;
this->high=new int (*(s.high));
}
};
int main()
{
int n=22;
int high=100;
Stu *p = new Stu{"张三",n,100,&high};
Stu *p1=new Stu(*p);
delete p;
return 0;
}
c++day3
最新推荐文章于 2024-07-23 18:35:33 发布