[英]make_shared with template constructor
I have a class with a template constructor, and want to have a shared_pointer
to it. 我有一个带有模板构造函数的类,并希望有一个
shared_pointer
。 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. 我知道
make_shared
的行不对,但不知道解决方案。 Is it even possible to call make_shared
with a template constructor? 是否可以使用模板构造函数调用
make_shared
? Do I need to make the 'New' function a template one and pass in A<T>
somehow?... 我是否需要将“新”功能设为模板并以某种方式传入
A<T>
?...
Convert A::New
into a function template 将
A::New
转换为函数模板
template<typename T>
static A_ptr New(Arg1 arg1, Arg2 arg2, T data) {
return std::make_shared<A>(arg1,arg2,data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.