5
我不能得到std::bind
以相同的方式工作boost::bind
工作。要麼我沒有正確使用它,要麼我的編譯器(GCC 4.4.5)還沒有正確實現它。std :: bind不工作
我有兩個功能:
void f(int x, int y)
{
cout << x << " | " << y << endl;
}
template <class UnaryFunction>
void g(UnaryFunction func)
{
func(100);
}
我使用綁定調用f
作爲g的一元函數:
g(std::bind(f, 10, std::placeholders::_1));
這將導致一個編譯器錯誤:
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
的語義在某種程度上是不同的,還是這是一個編譯器問題?
AFAIK std :: bind和boost :: bind在實現中不同,工作方式不同,boost :: bind具有更多的靈活性 – 2011-04-16 23:27:42