2012-08-28 43 views
0

我試圖使用升壓scope_guard編譯錯誤而發送的成員函數的函數指針

我需要發送一個成員函數的函數指針make_guard功能

我嘗試按以下方式:

class A 
{ 
    HRESULT foo(int x); 
    HRESULT foo_1(int x); 
} 

STDMETHODIMP A::foo(int x) 
{....}; 

STDMETHODIMP A::foo_1(int x) 
{ 

    boost::scope_guard xyz= 
    boost::make_guard(&A::foo, x); 
} 

但它給編譯錯誤:

E:\ThirdPartyCore\Boost\1_43_0\winx64\include\boost/multi_index/detail/scope_guard.hpp(103) : error C2064: term does not evaluate to a function taking 1 arguments 
     E:\ThirdPartyCore\Boost\1_43_0\winx64\include\boost/multi_index/detail/scope_guard.hpp(103) : while compiling class template member function 'void boost::multi_index::detail::scope_guard_impl1<F,P1>::execute(void)' 
     with 
     [ 
      F=HRESULT (__cdecl A::*)(int), 
      P1=int 
     ] 
     see reference to class template instantiation 'boost::multi_index::detail::scope_guard_impl1<F,P1>' being compiled 
     with 
     [ 
      F=HRESULT (__cdecl A::*)(int), 
      P1=int 
     ] 

AGPSEngine - 1 error(s), 0 warning(s) 

任何機構都可以幫我修理它。

回答

0

就像錯誤信息所說的,A::foo不是一個帶參數的函數;它是一個成員函數。我相信你想用obj_scope_guardmake_obj_scope_guard,通過this