Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does std::move result in slicing?

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>?

like image 654
user383352 Avatar asked Jan 22 '23 17:01

user383352


1 Answers

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.

like image 61
James McNellis Avatar answered Jan 24 '23 07:01

James McNellis