如何继承模板struct operator()?

时间:2013-01-21 08:37:12

标签: c++ templates

我试试

template<class T>
struct getData
{
    boost::shared_ptr<T> operator()()
    {
        return boost::shared_ptr<T>(new T());
    }
};

struct getVector : public getData<std::vector<int>>{};

我想通过继承来指定()返回...但它似乎没有返回所需的类型。我做错了什么?

1 个答案:

答案 0 :(得分:2)

您不需要返回类型

boost::shared_ptr<T> operator()()
^^^^^^^^^^^^^^^^^^^^
{
    return boost::shared_ptr<T>(new T());
}
相关问题