错误C2064: term不计算为一个带1个参数/使用模板的函数

error C2064: term does not evaluate to a function taking 1 arguments / using a template

本文关键字:参数 1个 函数 一个 term C2064 计算 错误      更新时间:2023-10-16

嗨,我得到这个错误信息时,试图编译这个:

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()
            {}

logger is type: 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.0VCincludememory(725): error C2064: term does not evaluate to a function taking 1 arguments
C:Program Files (x86)Microsoft Visual Studio 11.0VCincludememory(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:此处没有包含命名空间

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

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