class Empty {
public:
Empty(); // 缺省构造函数
Empty(const Empty& rhs); // 拷贝构造函数
~Empty(); // 析构函数 ---- 是否
// 为虚函数看下文说明
Empty&
operator=(const Empty& rhs); // 赋值运算符
Empty* operator&(); // 取址运算符
const Empty* operator&() const;
};
如果未声明上述函数,则编译器会自动生成上述函数.
如果有以下语句,则编译器会自动调用上述函数.
const Empty e1; // 缺省构造函数
// 析构函数
Empty e2(e1); // 拷贝构造函数
e2 = e1; // 赋值运算符
Empty *pe2 = &e2; // 取址运算符
// (非const)
const Empty *pe1 = &e1; // 取址运算符
// (const)
缺省构造函数和析构函数实际上什么也不做,它们只是让你能够创建和销毁类的对象.
缺省取址运算符只是返回对象的地址.这些函数实际上就如同下面所定义的那样:
inline Empty::Empty() {}
inline Empty::~Empty() {}
inline Empty * Empty::operator&() { return this; }
inline const Empty * Empty::operator&() const
{ return this; }
详见
http://www.kuqin.com/effectivec2e/ch12a.htm