While the goals and implementation of the copy-constructor and destructor are straightforward, the copy-assignment instead of providing our own, but this would be impossible; std::swap uses the copy-constructor and copy-assignment
一个类通过定义五种特殊的成员函数来控制这些操作,包括:拷贝构造函数( copy constructor)、拷贝赋值运算符( copy-assignment operator )、移动构造函数( moveconstructor
这是事实,只要我们正在开发的项目不关注看似琐碎的任务,如内存管理或发生在单一循环中的 copy-assignment 的数量。 相反,我们希望当内存分配和释放的时候,能够严格控制有多少 move-assignment 和 copy-assignment 被执行,并在编译时捕捉尽可能多的错误,而不是让错误渗入运行时(表现为运行时异常
std :: swap在实现中使用了copy-constructor和copy-assignment运算符,我们最终将尝试根据自身定义赋值运算符!
这是事实,只要我们正在开发的项目不关注看似琐碎的任务,如内存管理或发生在单一循环中的copy-assignment的数量。 相反,我们希望当内存分配和释放的时候,能够严格控制有多少move-assignment和copy-assignment被执行,并在编译时捕捉尽可能多的错误,而不是让错误渗入运行时(表现为运行时异常)。
一个类通过定义五种特殊的成员函数来控制这些操作: 拷贝构造函数copy constructor 拷贝赋值运算符copy-assignment operator 移动构造函数move constructor