C++ C++;问题:boost::bind接收其他boost::bind

C++ C++;问题:boost::bind接收其他boost::bind,c++,boost-bind,C++,Boost Bind,我想让这段代码正常工作,我应该怎么做 在最后一行给出此错误 我做错了什么? 我知道boost::bind需要一个类型,但我不知道。帮助 class A { public: template <class Handle> void bindA(Handle h) { h(1, 2); } }; class B { public: void bindB(int number, int number2)

我想让这段代码正常工作,我应该怎么做

在最后一行给出此错误

我做错了什么? 我知道boost::bind需要一个类型,但我不知道。帮助

class A
{

public:

    template <class Handle>
    void bindA(Handle h)
    {
        h(1, 2);
    }
};

class B
{

    public:
        void bindB(int number, int number2)
        {
            std::cout << "1 " << number << "2 " << number2 << std::endl;
        }
};


template < class Han > struct Wrap_
{

    Wrap_(Han h) : h_(h) {}

    template<typename Arg1, typename Arg2> void operator()(Arg1 arg1, Arg2 arg2)
    {
        h_(arg1, arg2);
    }
    Han h_;
};

template< class Handler >

    inline Wrap_<Handler> make(Handler h)
    {
        return Wrap_<Handler> (h);
    }
int main()
{

    A a;
    B b;
    ((boost::bind)(&B::bindB, b, _1, _2))(1, 2);
    ((boost::bind)(&A::bindA, a, make(boost::bind(&B::bindB, b, _1, _2))))();
/*i want compiled success and execute success this code*/

}
A类
{
公众:
模板
void bindA(手柄h)
{
h(1,2);
}
};
B类
{
公众:
void bindB(整数,整数2)
{

std::cout您遇到的问题是,您正试图绑定到模板化函数。在这种情况下,您需要指定要调用以绑定的方法的模板类型

对于方法
A::bindA
,会发生这种情况。请参阅下面的main代码片段,该代码片段可以使用提供的类正确编译

顺便提一下,在这个示例中,我使用了(绑定的姐妹库)来指定正在使用的函数指针的类型。我认为这使它更具可读性,并且强烈建议您在继续使用绑定时熟悉它

#include "boost/bind.hpp"
#include "boost/function.hpp"

int main(int c, char** argv)
{
  A a;
  B b;

  typedef boost::function<void(int, int)> BFunc;
  typedef boost::function<void(BFunc)> AFunc;
  BFunc bFunc( boost::bind(&B::bindB, b, _1, _2) );
  AFunc aFunc( boost::bind(&A::bindA<BFunc>, a, make(bFunc)) );

  bFunc(1,2);
}
#包括“boost/bind.hpp”
#包括“boost/function.hpp”
int main(int c,字符**argv)
{
A A;
B B;
typedef boost::函数BFunc;
typedef boost::函数AFunc;
BFunc BFunc(boost::bind(&B::bindB,B,_1,_2));
AFunc-AFunc(boost::bind(&A::bindA,A,make(bFunc));
bFunc(1,2);
}