C++ 如何继承模板结构运算符()?
我试着C++ 如何继承模板结构运算符()?,c++,templates,C++,Templates,我试着 模板 结构getData { boost::shared_ptr操作符()() { 返回boost::shared_ptr(新的T()); } }; struct getVector:public getData{}; 我想通过继承指定()返回。。。但它似乎没有返回所需的类型。我做错了什么?您不需要返回类型吗 template<class T> struct getData { boost::shared_ptr<T> operator()()
模板
结构getData
{
boost::shared_ptr操作符()()
{
返回boost::shared_ptr(新的T());
}
};
struct getVector:public getData{};
我想通过继承指定
()
返回。。。但它似乎没有返回所需的类型。我做错了什么?您不需要返回类型吗
template<class T>
struct getData
{
boost::shared_ptr<T> operator()()
{
return boost::shared_ptr<T>(new T());
}
};
struct getVector : public getData<std::vector<int>>{};
boost::shared_ptr操作符()()
^^^^^^^^^^^^^^^^^^^^
{
返回boost::shared_ptr(新的T());
}
确切的问题是什么?编译错误?不做您期望的事情?在派生类中也使用相同的语法。
boost::shared_ptr<T> operator()()
^^^^^^^^^^^^^^^^^^^^
{
return boost::shared_ptr<T>(new T());
}