void f(Base b); is called as f(derivedObject); where Derived publicly derives from Base and both override a virtual print(). What does b.print() call inside f?
ABase::print, because object slicing copies only the Base sub-object into the parameterCorrect answer
BIt is undefined behaviour, so either version may run depending on the optimisation level
CDerived::print, because the argument's dynamic type stays Derived inside the function
DDerived::print if Base's destructor is virtual, else Base::print, since dispatch depends on it
Correct answer
A. Base::print, because object slicing copies only the Base sub-object into the parameter
Object slicing occurs when a derived object is copied into a base value parameter, so the parameter is a genuine Base object and virtual dispatch finds Base::print. Passing by reference, Base& b, preserves the dynamic type and calls Derived::print. The same slicing happens when derived objects are stored by value in a std::vector<Base>.