C++默认生成4个成员函数.
默认构造函数(default constructor), 析构函数(destructor), 复制构造函数(copy constructor), 赋值构造函数(assignment);
C++11新增两个:
move构造函数(右值引用构造函数)
move赋值函数
如果满足位逐次拷贝(bitwise copy semantics),上述一个都不会生成
没有bitwise copy semantics的四种情况:
1、member object的声明有一个copy constructor,不论是否是自动生成。
2、继承的base class的声明有一个copy constructor,不论是否是自动生成。
3、class有虚函数
4、父类有虚函数
上述情况是因为:
class Animal
{
virtual void XXX(){}
};
class Bear : public Animal
{
void XXX(){}
};
Bear b;
Animal a = b;
/*如果单纯的bitwise copy,那么a就会指向Bear的vptr。a已经丢弃了b的部分属性,调用b的函数将会blow up
*/
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。