按照c++标准,编译器会生成五个默认成员函数:
- 默认构造函数
- 拷贝构造函数
- 析构函数
- operator=
- operator&
一个空的class在C++编译器处理过后就不再为空,编译器会自动地为我们声明一些member function,如果你写 :
class Empty {};
就相当于:
class Empty
{
public:
Empty();
Empty(const Empty&);
~Empty();
Empty& operator=(const Empty& rhs);
Empty* operator&();
const Empty* operator&() const;
};
需要注意的是只有当你需要用到这些函数的时候,编译器才会去定义它们。

浙公网安备 33010602011771号