使用mem_fun_ref与升压:: shared_ptr的 [英] Using mem_fun_ref with boost::shared_ptr

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

问题描述

页面的建议,我试图让shared_ptr的调用的IUnknown ::发布(),而不是删除:

  IDirectDrawSurface * DDS;
... //分配DDS
返回的shared_ptr< IDirectDrawSurface>(DDS,mem_fun_ref(安培;的IUnknown ::释放));


  

错误C2784:'的std :: const_mem_fun1_ref_t< _result,_Ty,_Arg>的std :: mem_fun_ref(结果(的_thiscall _Ty :: *)(_精氨酸)常量):无法推断出模板参数对于'的结果(的_thiscall _Ty :: *)(精氨酸)常量'从'ULONG(的_cdecl的IUnknown :: *)(无效)


  
  

错误C2784:'的std :: const_mem_fun_ref_t< _result,_Ty>的std :: mem_fun_ref(结果(的_thiscall _Ty :: *)(无效)常量):不能推导出模板参数为'的结果(的_thiscall _Ty :: *)从'ULONG(无效)常量(__cdecl的IUnknown :: *)(无效)


  
  

错误C2784:'的std :: mem_fun1_ref_t< _result,_Ty,_Arg>的std :: mem_fun_ref(结果(的_thiscall _Ty :: *)(_ ARG)):不能推导出模板参数为'的结果(的_thiscall _Ty :: *)( ARG)'从'ULONG(的_cdecl的IUnknown :: *)(无效)


  
  

错误C2784:'的std :: mem_fun_ref_t< _result,_Ty>的std :: mem_fun_ref(结果(的_thiscall _Ty :: *)(无效)):不能推导出模板参数为结果(的_thiscall _Ty :: *)从'ULONG(无效)(__cdecl的IUnknown :: *)(无效)


  
  

错误C2661:提高:: shared_ptr的:: shared_ptr的':没有重载函数需要两个参数


我不知道做这个东西。我有限的模板/仿函数知识使我试试

 的typedef ULONG(的IUnknown :: * releaseSignature)(无效);
shared_ptr的< IDirectDrawSurface>(DDS,mem_fun_ref(的static_cast< releaseSignature>(安培;的IUnknown ::释放)));

但无济于事。任何想法?


解决方案

不是调用约定说明问题吗?这是否OK?

 无效iUnk_delete(的IUnknown * U){
  U->发行();
}
返回的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与升压:: shared_ptr的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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