Class member function generated by default for C + + NULL class

Source: Internet
Author: User

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.

   
  
  1. //C++ 空类默认产生的类成员函数:
  2. //缺省构造函数,拷贝构造函数,析构函数,赋值运算符,取址运算符,取址运算符 const
  3. #include<iostream>
  4. using namespace std;
  5. class class1{
  6. public:
  7. class1(){}//缺省构造函数
  8. class1(const class1&){}//拷贝构造函数
  9. ~class1(){}//析构函数
  10. class1&operator=(const class1&){}//赋值运算符
  11. class1*operator&(){}//取址运算符
  12. const class1*operator&()const{}//取址运算符 const
  13. };
  14. //空类class2会产生class1一样的成员函数
  15. class class2{};
  16. void main()
  17. {
  18. class2 obj1;//缺省构造函数
  19. class2 obj2;
  20. obj1=obj2;//赋值运算符
  21. &obj2;//取址运算符
  22. class2 obj3(obj1);//拷贝构造函数
  23. class2 const obj4;
  24. &obj4;//取址运算符 const
  25. }



From for notes (Wiz)

Class member function generated by default for C + + NULL class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.