1

boost::functionを使用して、コールバックとして機能する関数に渡したいと思います。メンバー関数の割り当てに問題があるようです。

渡したい関数は静的関数です(別のスレッドで呼び出されるため)。

boost::function<std::string (ResolverReply& reply)> call_back = std::bind1st(std::mem_fun(&ResolverCommunicator::reply_call_back), *this);

これはResolverCommunicatorクラス内にありますが、私のコンパイラは次のことについて文句を言います。

_Right: reference to reference is illegal

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(278): error C2535: 'std::binder1st<_Fn2>::result_type std::binder1st<_Fn2>::operator ()(std::binder1st<_Fn2>::argument_type & ) const' : member function already defined or declared
        with
        [
            _Fn2=std::mem_fun1_t<std::string,ResolverCommunicator,ResolverReply &>
        ]
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(272) : see declaration of 'std::binder1st<_Fn2>::operator`()''
        with
        [
            _Fn2=std::mem_fun1_t<std::string,ResolverCommunicator,ResolverReply &>
        ]

call_back次に、別のスレッドで呼び出される静的関数に渡します。

誰かが何が悪いのか知っていますか?

編集:

私は答えが言うようにやったが、今私はこのエラーを受け取る:

 error C2665: 'boost::bind' : none of the 3 overloads can convert parameter 2 from type 'ResolverCommunicator'
        c:\Program Files\boost\boost_1_44\boost\bind\bind.hpp(1480): could be 'boost::_bi::bind_t<R,F,L> boost::bind<std::string(__thiscall ResolverCommunicator::* )(ResolverReply &),ResolverCommunicator,boost::arg<I>>(F,A1,A2)'
        with
        [
            R=boost::_bi::unspecified,
            F=std::string (__thiscall ResolverCommunicator::* )(ResolverReply &),
            L=boost::_bi::list2<boost::_bi::list_av_2<ResolverCommunicator,boost::arg<1>>::B1,boost::_bi::list_av_2<ResolverCommunicator,boost::arg<1>>::B2>,
            I=1,
            A1=ResolverCommunicator,
            A2=boost::arg<1>
        ]
        c:\Program Files\boost\boost_1_44\boost\bind\bind_mf_cc.hpp(43): or       'boost::_bi::bind_t<R,F,L> boost::bind<std::string,ResolverCommunicator,ResolverReply&,ResolverCommunicator,boost::arg<I>>(R (__thiscall ResolverCommunicator::* )(B1),A1,A2)'
        with
        [
            R=std::string,
            F=boost::_mfi::mf1<std::string,ResolverCommunicator,ResolverReply &>,
            L=boost::_bi::list2<boost::_bi::list_av_2<ResolverCommunicator,boost::arg<1>>::B1,boost::_bi::list_av_2<ResolverCommunicator,boost::arg<1>>::B2>,
            I=1,
            B1=ResolverReply &,
            A1=ResolverCommunicator,
            A2=boost::arg<1>
        ]
        c:\Program Files\boost\boost_1_44\boost\bind\bind_mf_cc.hpp(54): or       'boost::_bi::bind_t<R,F,L> boost::bind<std::string,ResolverCommunicator,ResolverReply&,ResolverCommunicator,boost::arg<I>>(R (__thiscall ResolverCommunicator::* )(B1) const,A1,A2)'
        with
        [
            R=std::string,
            F=boost::_mfi::cmf1<std::string,ResolverCommunicator,ResolverReply &>,
            L=boost::_bi::list2<boost::_bi::list_av_2<ResolverCommunicator,boost::arg<1>>::B1,boost::_bi::list_av_2<ResolverCommunicator,boost::arg<1>>::B2>,
            I=1,
            B1=ResolverReply &,
            A1=ResolverCommunicator,
            A2=boost::arg<1>
        ]
        while trying to match the argument list '(std::string (__thiscall
 ResolverCommunicator::* )(ResolverReply &), ResolverCommunicator, boost::arg<I>)'
        with
        [
            I=1
        ]
4

1 に答える 1

5

標準バインダーの既知の制限は、参照によってパラメーターを取る関数を処理しないことです。次の使用を検討する必要がありますboost::bind

boost::function<std::string (ResolverReply& reply)> call_back =
    boost::bind(&ResolverCommunicator::reply_call_back, this, _1);
于 2011-01-06T10:15:35.223 に答える