Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 绑定不工作_C++_C++11_Bind - Fatal编程技术网

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));