Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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++ 使用std::bind和lambda函数_C++ - Fatal编程技术网

C++ 使用std::bind和lambda函数

C++ 使用std::bind和lambda函数,c++,C++,以下代码未编译: auto greater_than = [](const int a, const int b) { return a > b; }; auto is_adult = bind(&greater_than, placeholders::_1, 17); cout << "Age 19 is adult = " << is_adult(19) << endl; 但是,如果我将移动到大于的位置,使其成为一个全局

以下代码未编译:

auto greater_than = [](const int a, const int b) { return a > b; };
auto is_adult = bind(&greater_than, placeholders::_1, 17);
cout << "Age 19 is adult = " << is_adult(19) << endl;
但是,如果我将
移动到大于
的位置,使其成为一个全局函数,那么它就会工作


为什么会这样?

删除
&
。即使指向函数的指针是可调用的,指向重载的
操作符()的对象的指针也是不可调用的。

删除
&
。即使指向函数的指针是可调用的,指向重载的
运算符()的对象的指针也是不可调用的。

删除
&
。仅供参考:删除
&
。仅供参考:
error: no matching function for call to object of type 'std::_Bind<(lambda at main.cpp:62:23) *(std::_Placeholder<1>, int)>'