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 ++>