我无法std::bind以同样的方式boost::bind工作.要么我没有正确使用它,要么我的编译器(GCC 4.4.5)没有正确实现它.
我有两个功能:
void f(int x, int y)
{
cout << x << " | " << y << endl;
}
template <class UnaryFunction>
void g(UnaryFunction func)
{
func(100);
}
Run Code Online (Sandbox Code Playgroud)
我使用bind f作为g中的一元函数调用:
g(std::bind(f, 10, std::placeholders::_1));
Run Code Online (Sandbox Code Playgroud)
这会导致编译器错误:
error: no match for call to ‘(std::_Bind<void (*(int, std::_Placeholder<1>))(int, int)>) (int)’
Run Code Online (Sandbox Code Playgroud)
...后跟一个页面左右的模板编译器呕吐.
如果我使用boost::bind,像:
g(boost::bind(f, 10, _1));
Run Code Online (Sandbox Code Playgroud)
......工作正常 语义是否std::bind有所不同,或者这是编译器问题?
| 归档时间: |
|
| 查看次数: |
1287 次 |
| 最近记录: |