代码拉取完成,页面将自动刷新
#include<iostream>
using namespace std;
//class Person
//{
//public:
// Person()
// {
// cout << "Person默认构造函数已调用" << endl;
// }
// Person(int age)
// {
// cout << "Person有参构造函数已调用" << endl;
// m_Age = age;
// }
// Person(const Person &p)
// {
// cout << "Person拷贝构造函数已调用" << endl;
// m_Age = p.m_Age;
// }
// ~Person()
// {
// cout << "Person析构函数已调用" << endl;
// }
// int m_Age;
//};
////1.使用一个已经创建完毕的对象来初始化一个新对象
//void test01()
//{
// Person p1(10);
// Person p2(p1);
// cout << "p2的年龄是:" << p2.m_Age << endl;
//}
////2.值传递的方式给函数参数传值
//void doWork(Person p)
//{
//
//}
//
//void test02()
//{
// Person p;//调用了默认构造函数
// doWork(p);//在值传递时(临时拷贝数据时)调用了拷贝构造函数
//}
//
////3.值方式返回局部对象
//Person doWork2()
//{
// Person p1;
// cout << (int*)&p1 << endl;
// return p1;//返回值时调用了拷贝构造函数
//
//}
//void test03()
//{
// Person p=doWork2();
// cout << (int*)&p << endl;
//
//}
//
//int main()
//{
// //test01();
// //test02();
// test03();
//
// return 0;
//}
class Printer {
public:
Printer(std::string name) { std::cout << name; }
};
class Container {
public:
Container() : b("b"), a("a") {}
Printer a;
Printer b;
};
int main() {
Container c;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。