#include <iostream>
using namespace std;
class Per
{
private:
string name;
int age;
float *height;
float *weight;
public:
Per()//无参构造函数
{
cout << "无参构造函数" << endl;
}
Per(string name,int age,float *height,float *weight) //有参构造函数
{
cout << "有参构造函数" << endl;
}
~Per()
{
cout << "析构函数" << endl;
}
Per(const Per &other):name(other.name),age(other.age),height(other.height),weight(other.weight)//拷贝构造函数
{
cout << "拷贝构造函数" << endl;
}
};
class Stu
{
private:
double score;
Per p1;
public:
Stu()
{
cout << "无参构造函数" << endl;
}
Stu(double score ,string name,int age,float *height,float *weight):score(score),p1(name,age,height,weight)
{
cout << "有参构造函数" << endl;
}
~Stu()
{
cout << "析构函数" << endl;
}
Stu(const Stu &other):score(other.score),p1(other.p1)
{
cout << "拷贝构造函数" << endl;
}
};
int main()
{
Per p1;
float h=180;
float w=10;
Per p2("zz",11,&h,&w);
Per p3=p2;
Stu s1;
Stu s2(100,"xx",22,&h,&w);
Stu s3=s2;
return 0;
}
10.9作业
最新推荐文章于 2024-11-14 19:11:37 发布