How can I call make_shared
or make_unique
on a class that has a templated constructor? Here's an example:
class A
{
/// constructor shared ptr
A(shared_ptr<X> x) ...
/// constructor that creates new shared ptr
template <class T> A() : A(make_shared<T>(...)) {}
};
make_shared<A<T>>()
doesn't make sense (nor does it compile), since that would rather be for a templated class, not a templated constructor.
Neither make_shared<A><T>()
nor make_shared<A>(<T>())
compile---nor look like they should. Ditto on make_shared<A, T>()
Is there any way to specify the template for the constructor call in the call to make_shared
? I assume the answer would apply for make_unique
; if it doesn't, please indicate that. Thanks!
(To clarify how the templating is working, I've edited the code.)