使用mem_fun_ref和boost :: shared_ptr [英] Using mem_fun_ref with boost::shared_ptr

查看:137
本文介绍了使用mem_fun_ref和boost :: shared_ptr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照此网页的建议,我想获得shared_ptr调用 IUnknown :: Release(),而不是删除:

  IDirectDrawSurface * dds; 
... //分配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)':无法推导出'em'结果的模板参数( _thiscall _Ty :: * ( Arg)const'from'ULONG( _cdecl IUnknown :: *)(void)'



错误C2784:'std :: const_mem_fun_ref_t& _Result,_Ty> std :: mem_fun_ref(结果( _thiscall _Ty :: *)(void)const)':无法推导出'em'结果的模板参数( _thiscall _Ty: :*)(void)const'from'ULONG(__cdecl IUnknown :: *)(void)'



错误C2784:'std :: mem_fun1_ref_t <_Result, _Arg> std :: mem_fun_ref( result( _thiscall _Ty :: *)(_Arg))':无法推导出'em'结果的模板参数( _thiscall _Ty :: * ( Arg)'from'ULONG( _cdecl IUnknown :: *)(void)'



错误C2784:'std :: mem_fun_ref_t< _Result ,_Ty> std :: mem_fun_ref( _thiscall _Ty :: *)(void))':无法推导出'em'结果的模板参数( _thiscall _Ty :: * )void''''''''''''''''''''''''''''''''需要2个参数


我不知道该怎么做。我有限的模板/函子知识让我尝试

  typedef ULONG(IUnknown :: * releaseSignature) 
shared_ptr< IDirectDrawSurface>(dds,mem_fun_ref(static_cast< releaseSignature>(& IUnknown :: Release))));

但没有效果。任何想法?

解决方案

调用约定规范不是一个问题吗?这是否可以?

  void iUnk_delete(IUnknown * u){
u->
}


return shared_ptr< IDirectDrawSurface>(dds,iUnk_delete);


Following the advice of this page, I'm trying to get shared_ptr to call IUnknown::Release() instead of delete:

IDirectDrawSurface* dds;
... //Allocate dds
return shared_ptr<IDirectDrawSurface>(dds, mem_fun_ref(&IUnknown::Release));

error C2784: 'std::const_mem_fun1_ref_t<_Result,_Ty,_Arg> std::mem_fun_ref(Result (_thiscall _Ty::* )(_Arg) const)' : could not deduce template argument for 'Result (_thiscall _Ty::* )(Arg) const' from 'ULONG (_cdecl IUnknown::* )(void)'

error C2784: 'std::const_mem_fun_ref_t<_Result,_Ty> std::mem_fun_ref(Result (_thiscall _Ty::* )(void) const)' : could not deduce template argument for 'Result (_thiscall _Ty::* )(void) const' from 'ULONG (__cdecl IUnknown::* )(void)'

error C2784: 'std::mem_fun1_ref_t<_Result,_Ty,_Arg> std::mem_fun_ref(Result (_thiscall _Ty::* )(_Arg))' : could not deduce template argument for 'Result (_thiscall _Ty::* )(Arg)' from 'ULONG (_cdecl IUnknown::* )(void)'

error C2784: 'std::mem_fun_ref_t<_Result,_Ty> std::mem_fun_ref(Result (_thiscall _Ty::* )(void))' : could not deduce template argument for 'Result (_thiscall _Ty::* )(void)' from 'ULONG (__cdecl IUnknown::* )(void)'

error C2661: 'boost::shared_ptr::shared_ptr' : no overloaded function takes 2 arguments

I have no idea what to make of this. My limited template/functor knowledge led me to try

typedef ULONG (IUnknown::*releaseSignature)(void);
shared_ptr<IDirectDrawSurface>(dds, mem_fun_ref(static_cast<releaseSignature>(&IUnknown::Release)));

But to no avail. Any ideas?

解决方案

Isn't the calling convention specifier a problem? Would this be OK?

void iUnk_delete(IUnknown* u) {
  u->Release();
}


return shared_ptr<IDirectDrawSurface>(dds, iUnk_delete);

这篇关于使用mem_fun_ref和boost :: shared_ptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆