拷贝构造函数??

猜猜下面的代码结果是什么??

#include <iostream>
using namespace std;
class A
{
public:
	A() {}
	A(const A& a) { cout << "copy " << endl;}
	A& operator=(const A&a) { cout << "== " << endl;
	return *this;
	}
};
int main()
{
	A b;
	A a = b;
	return 0;
}

答案是copy 哈哈哈。

即使赋值运算符被重载了,这种情况也是用的拷贝构造函数

发布了81 篇原创文章 · 获赞 4 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/m0_37313888/article/details/105234268