std :: bind无法正常工作

时间:2011-04-16 23:25:12

标签: c++ c++11 bind

我无法std::bindboost::bind的方式工作void f(int x, int y) { cout << x << " | " << y << endl; } template <class UnaryFunction> void g(UnaryFunction func) { func(100); } 。要么我没有正确使用它,要么我的编译器(GCC 4.4.5)没有正确实现它。

我有两个功能:

f

我使用bind来调用g(std::bind(f, 10, std::placeholders::_1)); 作为g:

中的一元函数
error: no match for call to ‘(std::_Bind<void (*(int, std::_Placeholder<1>))(int, int)>) (int)’

这会导致编译器错误:

boost::bind

...后面是一个页面左右的模板编译器呕吐。

如果我使用g(boost::bind(f, 10, _1)); ,例如:

std::bind

......它运作正常。 {{1}}的语义是否有所不同,或者这是编译器问题?

1 个答案:

答案 0 :(得分:5)

看起来它只是你的编译器版本,gcc 4.5.1(via ideone.com)和4.6.0正确编译它。