(For vptr during slicing, see other posts)
Q: Any Slicing when func1(const B& b) receives a D argument?
A: no, since there’s just _one_ object (see posts on implicit cloning). But not sure afterwards.
Background — On the “real estate” of the Single-Inheritance D object, there is a B object, like a basement. B’s real estate is part of D’s real estate — these 2 objects share[3] the same “postal address”, making pointer casting possible.
[3] with multiple inheritance, Derived object and the embedded Base sub-object don’t necessarily share the same postal address of “this”
(Warning: AOB is inapplicable for multiple-inheritance. See other posts for details.) In the opening question, when you get a B ref to a D object, you get the address of the basement (AOB). Using this B reference, you can access B’s fields only. To access D’s fields, you must downcast a B ptr into a D ptr. AOB is the basis of most if not all slicing problems such as
* copy ctor qq( B b=d ) — In the implicit copier call, the implicit param “const B&” gets the AOB so can only access the B fields of the D object. After the copier call, the LHS becomes a sliced copy of the D.
* assignment qq( B b; b=d ) — The param “const B&” gets the AOB so can only access the B fields of the D object. LHS becomes a sliced copy of the D.
Remember the onion — slice off the outer layer.