I have a base class and its subclass:
class Base {
public:
virtual void hi() {
cout << \"hi\" << endl;
}
};
class Derived : pub
You will find that std::unique_ptr can move from derived's to base's, if you look into its definition. Basically is_convertible
here check this situation.
/** @brief Converting constructor from another type
*
* Requires that the pointer owned by @p __u is convertible to the
* type of pointer owned by this object, @p __u does not own an array,
* and @p __u has a compatible deleter type.
*/
template,
typename conditional::value,
is_same<_Ep, _Dp>,
is_convertible<_Ep, _Dp>>::type>>
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
: _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter()))
{ }