What are the member functions of the empty class for C + +:
. The default constructor.
. The default copy constructor.
. The default destructor.
. The default assignment operator.
. The default accessor operator.
. The default accessor operator is Const.
Note: Some books simply introduce the first four functions (treasure 4th p112). The following two functions are not mentioned. However, the latter two functions are also the default functions of the Empty class (Ref:effective C + +). It is also important to note that only when these functions are actually used does the compiler define them.
//C++ 空类默认产生的类成员函数:
//缺省构造函数,拷贝构造函数,析构函数,赋值运算符,取址运算符,取址运算符 const
#include<iostream>
using namespace std;
class class1{
public:
class1(){}//缺省构造函数
class1(const class1&){}//拷贝构造函数
~class1(){}//析构函数
class1&operator=(const class1&){}//赋值运算符
class1*operator&(){}//取址运算符
const class1*operator&()const{}//取址运算符 const
};
//空类class2会产生class1一样的成员函数
class class2{};
void main()
{
class2 obj1;//缺省构造函数
class2 obj2;
obj1=obj2;//赋值运算符
&obj2;//取址运算符
class2 obj3(obj1);//拷贝构造函数
class2 const obj4;
&obj4;//取址运算符 const
}
From for notes (Wiz)
Class member function generated by default for C + + NULL class