0
点赞
收藏
分享

微信扫一扫

拷贝构造函数

米小格儿 2022-01-13 阅读 34
#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 条评论