代码拉取完成,页面将自动刷新
#include<iostream>
using namespace std;
class Person
{
public:
Person()
{
cout << "Person的无参构造函数已调用" << endl;
}
Person(int a)
{
age = a;
cout << "Person的有参构造函数已调用" << endl;
}
//拷贝构造函数
Person(const Person& p)
{
cout << "拷贝析构函数已调用" << endl;
age = p.age;
}
~Person()
{
cout << "Person的析构函数已调用" << endl;
}
int age;
};
void test01()
{
//括号法
/*Person p1;
Person p2(10);
Person p3(p2);
cout << "p2的年龄是:" << p2.age << endl;
cout << "p3的年龄是:" << p3.age << endl;*/
//2.显示法
/*Person p1;
Person p2 = Person(10);
Person p3 = Person(p2);*/
//3.隐式转换法
Person p4 = 10;
Person p5 = p4;
}
int main()
{
test01();
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。