错误C2064:术语不评估为使用1个参数/使用模板的函数

时间:2014-07-10 15:15:24

标签: c++ templates c++11

您好,我在尝试编译时收到此错误消息:

template<typename T>
std::shared_ptr<T> sptr(T* ptr)
{
 return std::shared_ptr<T>(ptr, &extension::IDeleteable::destroy);
}

costructorA(const Logger& _logger):logger(sptr(_logger.clone())) //here the error using sptr()
            {}

记录器的类型为:std::shared_ptr<Logger> logger;

class Logger是:

    class GMRISK_FCUL_API Logger  : public IDeleteable{
    public:
        virtual ~Logger() {}
        virtual void destroy() const =0;
    };

class IDeleateable

class IDeleteable
{
    public:
        virtual void destroy() const =0;

        template<typename T>
        static inline void destroy(T* value)
        {
            value->destroy();
        }
};

这里有完整的错误:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(725): error C2064: term does not evaluate to a function taking 1 arguments
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(494) : see reference to function template instantiation 'void std::shared_ptr<_Ty>::_Resetp<_Ux,_Dx>(_Ux *,_Dx)' being compiled
      with
      [
          _Ty=gmrisk::fcul::Logger,
          _Ux=gmrisk::fcul::Logger,
          _Dx=void (__thiscall extension::IDeleteable::* )(void) const
      ]
fcul_api.cpp(34) : see reference to function template instantiation 'std::shared_ptr<_Ty>::shared_ptr<T,void(__thiscall extension::IDeleteable::* )(void) const>(_Ux *,_Dx)' being compiled
      with
      [
          _Ty=gmrisk::fcul::Logger,
          T=gmrisk::fcul::Logger,
          _Ux=gmrisk::fcul::Logger,
          _Dx=void (__thiscall extension::IDeleteable::* )(void) const
      ]

任何可以产生这种想法的想法?

PD:这里没有包含名称空间

1 个答案:

答案 0 :(得分:2)

要获取指向静态成员函数模板的指针,您需要显式实例化它:

return std::shared_ptr<T>(ptr, &extension::IDeleteable::destroy<T>);
                                                               ^^^