繼this page的建議,我試圖讓shared_ptr的調用IUnknown::Release()而不是刪除:使用mem_fun_ref與升壓:: shared_ptr的
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)常量) ':不能推導出模板參數'從' ULONG _result(__thiscall _Ty :: *)(_ ARG)常量(__cdecl的IUnknown :: *)(無效) '
錯誤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 :: *)(無效)」
錯誤C2784: '的std :: mem_fun1_ref_t < _result,_Ty,_Arg>的std :: mem_fun_ref(_result(__thiscall _Ty :: *)(_ ARG))':不能推導出模板參數爲'_result(__thiscall _Ty :: *)(_精氨酸)' 從 'ULONG(__cdecl的IUnknown :: *)(無效)'
錯誤C2784:「的std :: mem_fun_ref_t < _result,_Ty>的std :: mem_fun_ref(_result (__thiscall _Ty :: *)(無效))」:不能推導出模板參數'從 'ULONG _result(__thiscall _Ty :: *)(無效)(__cdecl的IUnknown :: *)(無效)'
錯誤C2661: '提高:: shared_ptr的:: shared_ptr的':沒有重載函數採用2個參數
我不知道本作的是什麼。我有限的模板/函數知識讓我去嘗試
typedef ULONG (IUnknown::*releaseSignature)(void);
shared_ptr<IDirectDrawSurface>(dds, mem_fun_ref(static_cast<releaseSignature>(&IUnknown::Release)));
但無濟於事。有任何想法嗎?
呃,哇,工作。謝謝!你知道爲什麼[這個問題]的答案(http://stackoverflow.com/questions/441306/make-shared-ptr-not-use-delete)完全使用'ptr_fun'嗎? – 2010-05-14 02:22:45