拷贝构造函数

阅读 35

2022-01-13

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

class Object
{
public:
	int a;

	Object() : a(0)
	{
		printf("construct\n");
	}

	Object(const Object& _object) : a(_object.a) 
	{
		printf("copy construct\n");
	}

	~Object()
	{
		printf("delete\n");
	}
};

Object fun()
{
	Object o;
	return o;
}

int main()
{
	Object o = fun();
	return 0;
}

construct
copy construct
delete
delete

拷贝构造函数只执行了一次

精彩评论(0)

0 0 举报