I have a class with a template constructor, and want to have a shared_pointer to it. Such as:
class A;
typedef std::shared_ptr<A> A_ptr;
class A {
public:
template <typename T>
A(Arg1 arg1, Arg2 arg2, T data) { ... do something with data ... }
static A_ptr New(Arg1 arg1, Arg2 arg2, T data) {
return make_shared<A>(arg1,arg2,data);
}
};
I know the line for the make_shared isn't right, but don't know the solution. Is it even possible to call make_shared with a template constructor? Do I need to make the 'New' function a template one and pass in A<T> somehow?...
Convert A::New into a function template
template<typename T>
static A_ptr New(Arg1 arg1, Arg2 arg2, T data) {
return std::make_shared<A>(arg1,arg2,data);
}
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