发送成员函数的函数指针时编译错误

时间:2012-08-28 09:52:23

标签: c++ boost

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

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

1 个答案:

答案 0 :(得分:0)

与错误消息一样,A::foo不是一个带一个参数的函数;它是一个成员函数。我相信你想使用obj_scope_guardmake_obj_scope_guard,传递this