avisnet's blog

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

按照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;

};

需要注意的是只有当你需要用到这些函数的时候,编译器才会去定义它们。

posted on 2006-09-22 14:52  avisnet  阅读(442)  评论(0)    收藏  举报