#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
class Person
{
public:
Person();
Person(int a);
Person(const Person& p);
~Person();
int m_Age;
private:
};
Person::Person()
{
cout << "无参构造" << endl;
}
Person::Person(int a)
{
cout << "有参构造" << endl;
m_Age = a;
}
Person::Person(const Person& p)
{
cout << "拷贝构造" << endl;
m_Age = p.m_Age;
}
Person::~Person()
{
cout << "析构调用" << endl;
}
//1、用已经构建好的对象来初始化新的对象
void test01()
{
Person p1;
p1.m_Age = 10;
Person p2(p1);
}
//2、以值传递的方式给函数传值
void DoWork(Person &p1)
{
}
//3、以值的方式返回局部对象
Person DoWork2()
{
Person p;
return p;
}
int main()
{
system("pause");
return EXIT_SUCCESS;
}
C++基础学习DAY3-05 拷贝构造函数的调用时机
最新推荐文章于 2023-01-07 09:22:24 发布