For example, in
unique_ptr<Derived> = new deriv;
std::vector<unique_ptr<Base>>.push_back(std::move(deriv));
will deriv be sliced to type unique_ptr<Base>
?
No slicing will occur; the unique_ptr<Base>
will own the pointer to the Derived
object.
A unique_ptr
to a derived class can be implicitly converted to a unique_ptr
to a base class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With