That depends entirely whether the constructor takes its argument by reference/pointer. If it does not, the object will be sliced into a ClassA<Type>
.
#include <memory>
template <typename Type>
class ClassA {};
class ClassB : public ClassA<Animal> {};
template <typename Type>
class ClassUser1 {
public:
explicit ClassUser1(ClassA<Type>);
}
template <typename Type>
class ClassUser2 {
public:
explicit ClassUser2(std::unique_ptr<ClassA<Type>>);
}
In this setup, calling ClassUser1<Animal>::ClassUser1{ClassB{}}
will construct a temporary ClassB
, which will be used to move-construct a ClassA<Animal>
(slicing the object).
Calling ClassUser2<Animal>::ClassUser2{std::make_unique<ClassB>()}
will work as you would expect; the pointed-to instance remains a ClassB
.