Find out the functions written and called by C ++ behind the scenes

Source: Internet
Author: User
 
Clause 45: Find out the functions written and called by C ++ behind the scenes

When is an empty class not an empty class? ----
When the C ++ compiler passes through it. If you do not declare the following functions, the considerate compiler will declare its own version. These functions are: A copy constructor, a value assignment operator, a destructor, and a pair of access operators. In addition, if you do not declare any constructor, it will also declare a default constructor for you. All these functions are public. In other words, if you write:

Class empty {};

This is the same as writing:

Class empty {
Public:
Empty (); // default constructor
 
Empty (const empty & RHs); // copy the constructor

~ Empty (); // destructor ----
Whether
// For the virtual function, see the following description
Empty &
 
Operator = (const empty & RHs); // value assignment operator

Empty * operator & (); // address fetch Operator
Const empty *
Operator & () const;
};

Now, if necessary, these functions will be generated, but you will need them easily. The followingCodeEach function is generated:

Const empty E1 ;//
Default constructor
// Destructor

Empty E2 (E1); // copy the constructor

E2 = e1; // value assignment operator

Empty * Pe2 = & E2 ;//
Address fetch Operator
// (Non-const)

Const empty * pe1 = & E1 ;//
Address fetch Operator
// (Const)

From: <valid tive C ++>

Related Article

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.