本文介绍了[&]在功能前是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码行代表什么意思?
What do the follow row of code mean?
auto allowed = [&](int x, const std::vector<int>&vect){
....
}
我的意思是, [&]
是什么?因为它以这种方式使用: unsigned short ok = get_allowed(0,vect(),它是一个函数,它具有相同的变量名称
I mean, what does
[&]
do? and is it function with the same name of the variable??
推荐答案
这意味着lambda函数将捕获范围内的所有变量参考。
解决方案
要使用除了传递给lambda之外的其他变量,我们可以使用
capture-clause []
。
您可以通过引用和值捕获,您可以使用&和=分别:
It means that the lambda function will capture all variables in the scope by reference.
-
[=]
/ li>
-
[&]
通过引用获取范围内的所有变量 -
To use other variables other than what was passed to lambda within it, we can use
capture-clause []
.You can capture by both reference and value, which you can specify using & and = respectively:
这篇关于[&]在功能前是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!