copy ctor(assignment ctor) and slicing. Below four are all SLICING. number
5 and number 4 is not very obvious. They are call base class ctor.
No matter what you input a reference to a derived class or not.
Continue- Think this problem: Virtual Clone method. A function’s return
type is never considered part of its signature. You can override a
member function with any return type as long as the return type
could be used wherever the base class return type could be used.
Continue- Think this problem: Change Design. Base is concrete class, More
Effective C++ Item 33 said"Making Non-leaf class abstract. So maybe you
can change the inheritance system.
Assignment operator and copy ctor in inheritance:
Default Assignment operator and copy constructor inderived class which are implicitly produced by compilerwill call default base assignment operator and copyconstructor.
If derived class has no new operation. Don’t need to definederived class Assignment operator and copy constructor,implicit one will call base one automatically
If derived class has new operation. You have todefine derived class Assignment operator and copyconstructor, it will not invoke assignment operator andcopy constructor in base class any more. Inside, manuallyinvoke base class Assignment operator and copy ctor
Detail can be found in C++ primer p760. Syntax looks like below:
see effective C++ Item 16.
For copy ctor, just init list syntaxt. For assignment operator, use
two different methods depends on if base class declare its own
assignment operator(). Source code is below: