If the user does not provide constructors, copy constructors, copy assignment operators, and destructors, the compiler will help you create them only if they are needed. These functions generated by the compiler are public and inline.
When you write down a class like this:
class Empty {};
If the above function is required, then the compilation will automatically help you to change the class to the following:
class empty{ public // here is the default initialization of the data member, if there is a virtual function, This also configures the virtual function table Empty (const empty& RHS) {...} ~empty () {..} // empty& operator = (const empty&< Span style= "color: #000000;" > RHS) {...}};
Subject to detailed textual research in inside C + + object model (Note: In fact, for the copy constructor, assignment operator overloading, not you did not write yourself, when the need to be called when it was generated!) If the compiler determines that the required copy constructor for this class is trival, the trivial copy constructor, then the compiler will not generate a copy ' constructor, etc. , but only where it needs the copy constructor or assignment operator overloading. The execution of a bit-wise copy).
Second, note that the destructor of the compiler output is a non-vitual, unless the class's base class itself declares a virtual destructor.
Note that in a class containing reference members, the assignment operation is supported and you must define the copy assignment operator yourself. The same is true for the class with the const member included.
Otherwise the compiler will prompt you:
non-Static reference member ' std::stringdefaultoperator
Or
non-staticconst member 'conststringdefaultoperator
Iv. if a base class declares the copy assignment operator as private, the compiler will refuse to generate a copy assignment operator for its derived class.
Effective C + + learning NOTE Clause 05: Understand what functions C + + silently writes and calls