What is The Rule of Three?
首先摆明问题:
1、拷贝一个对象是什么意思?
2、拷贝构造函数和拷贝赋值运算符又都是什么?
3、在什么时候我需要声明他们?
4、我如何阻止我的对象被拷贝?
1、前言(Introduction)
C++看待用户定义的数据变量 with value semantics,这就意味着在不同的上下文中,对象都被拷贝。因此我们需要理解“copying an object” 到底意味着什么?
先看一个简单的例子:
6、the rule of three
If you need to explicitly declare either the destructor, copy constructor or copy assignment operator yourself, you probably need to explicitly declare all three of them.
如果你需要明确的声明析构函数,拷贝构造函数和拷贝赋值运算符,你可能需要显式声明他们三个。
原文地址:http://stackoverflow.com/questions/4172722/what-is-the-rule-of-three