【发布时间】:2016-10-05 07:50:50
【问题描述】:
我已经看到有很多关于使用 boost 的 make_shared() 和模板类的问题/答案,但是对于 C++ 来说,我似乎没有找到我想要的东西。 所以基本上我创建了一个名为 Generic 的类,它的管理器类 GenericManager 具有以下公共成员。
class GenericManager
{
public:
typedef boost::shared_ptr<GeneriClass> GenericClassPtr;
//... more members etc
};
现在我有另一个模板化的类,我想创建一个 make_shared 调用,即:
template <class MyType>
SpecificClass<MyType>::...
{
//class members functions etc
};
然后我想做的电话是:
GenericClassPtr SpecificClassFactory::construct()
{
return boost::make_shared<SpecificClass>();
}
这适用于 SpecificClass 的非模板版本,但对于模板版本我得到通常的错误:
error: no matching function for call to ‘make_shared()’
如何交替调用 make_shared 以接受模板类型?现在我尝试坚持使用 C++98!
编辑:@wasthishelpful 修正了提到的错字,谢谢。
【问题讨论】:
-
return boost::make_shared<SpecificClass<YourType> >();?