如何继承模板结构operator()

How to inherit template struct operator()?

本文关键字:operator 结构 继承 何继承      更新时间:2023-10-16

我试了试

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<T> operator()()
^^^^^^^^^^^^^^^^^^^^
{
    return boost::shared_ptr<T>(new T());
}