0

我正在尝试使用 boost 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)

任何人都可以帮我修复它。

4

1 回答 1

0

就像错误消息说的那样,A::foo不是一个带一个参数的函数;它是一个成员函数。相信你想用obj_scope_guardand make_obj_scope_guard,传递this

于 2012-08-28T09:58:16.020 回答