C++ 绑定不工作
我无法让C++ 绑定不工作,c++,c++11,bind,C++,C++11,Bind,我无法让std::bind以与boost::bind相同的方式工作。要么我没有正确地使用它,要么我的编译器(GCC4.4.5)还没有正确地实现它 我有两个职能: void f(int x, int y) { cout << x << " | " << y << endl; } template <class UnaryFunction> void g(UnaryFunction func) { func(100); }
std::bind
以与boost::bind
相同的方式工作。要么我没有正确地使用它,要么我的编译器(GCC4.4.5)还没有正确地实现它
我有两个职能:
void f(int x, int y)
{
cout << x << " | " << y << endl;
}
template <class UnaryFunction>
void g(UnaryFunction func)
{
func(100);
}
这将导致编译器错误:
error: no match for call to ‘(std::_Bind<void (*(int, std::_Placeholder<1>))(int, int)>) (int)’
…很好用。
std::bind的语义是否有所不同,或者这是一个编译器问题?看起来它只是您的编译器版本,gcc 4.5.1()和4.6.0正确编译了它。AFAIK std::bind和boost::bind在实现上不同,工作方式也不同,boost::bind具有更大的灵活性
error: no match for call to ‘(std::_Bind<void (*(int, std::_Placeholder<1>))(int, int)>) (int)’
g(boost::bind(f, 10, _1));