Effective C++ 条款05:了解C++编写并调用哪些函数

规则一 编译器默认操作

// 你认为
class Empty { };
// 实际上
class Empty {
public:
	Empty() { ... }                                 // default 构造函数
	Empty(const Empty& rhs) { ... }                 // copy 构造
	~Empty() { ... }                                // 析构函数
	Empty& operator=(const Empty& rhs) { ... }      // copy assignment 操作符
}
// 调用
Empty e1;      // default 构造函数
			   // 析构函数
Empty e2(e1);  // copy 构造函数
e2 = e1;       // copy assignment 操作符

总结

编译器可以暗自为class创建default构造函数、copy构造函数、copy assignment 操作符、析构函数。

原文地址:https://www.cnblogs.com/zhonghuasong/p/7295209.html