按照这个页面的建议,我试图让 shared_ptr 调用IUnknown::Release()而不是删除:
IDirectDrawSurface* dds;
... //Allocate dds
return shared_ptr<IDirectDrawSurface>(dds, mem_fun_ref(&IUnknown::Release));
错误 C2784: 'std::const_mem_fun1_ref_t<_Result,_Ty,_Arg> std::mem_fun_ref(_Result (__thiscall _Ty::* )(_Arg) const)' : 无法推断出 '_Result (__thiscall _Ty::* ) 的模板参数(_Arg) const' 来自 'ULONG (__cdecl IUnknown::* )(void)'
错误 C2784: 'std::const_mem_fun_ref_t<_Result,_Ty> std::mem_fun_ref(_Result (__thiscall _Ty::* )(void) const)' : 无法推导出 '_Result (__thiscall _Ty::* )(void ) const' 来自 'ULONG (__cdecl IUnknown::* )(void)'
错误 C2784: 'std::mem_fun1_ref_t<_Result,_Ty,_Arg> std::mem_fun_ref(_Result (__thiscall _Ty::* )(_Arg))' : 无法推断出 '_Result (__thiscall _Ty::* )的模板参数( _Arg)' 来自 'ULONG (__cdecl IUnknown::* )(void)'
错误 C2784: 'std::mem_fun_ref_t<_Result,_Ty> std::mem_fun_ref(_Result (__thiscall _Ty::* )(void))' : 无法推断出 '_Result (__thiscall _Ty::* )(void) 的模板参数'来自'ULONG (__cdecl IUnknown::*)(void)'
错误 C2661:'boost::shared_ptr::shared_ptr':没有重载函数需要 2 个参数
我不知道该怎么做。我有限的模板/函子知识使我尝试
typedef ULONG (IUnknown::*releaseSignature)(void);
shared_ptr<IDirectDrawSurface>(dds, mem_fun_ref(static_cast<releaseSignature>(&IUnknown::Release)));
但无济于事。有任何想法吗?