- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
来自 n3290 的观点:ISO 标准草案,§5.1.2/9
A lambda-expression whose smallest enclosing scope is a block scope (3.3.3) is a local lambda expression; any other lambda-expression shall not have a capture-list in its lambda-introducer. The reaching scope of a local lambda expression is the set of enclosing scopes up to and including the innermost enclosing function and its parameters. [ Note: This reaching scope includes any intervening lambda-expression's — end note ]
任何人都可以针对上述观点给出一个例子,尤其是:“其他 lambda 表达式不应在其 lambda 引入器中包含捕获列表。”这种情况出现在哪里?
最佳答案
这种情况理论上应该出现在命名空间范围内,如@Space_C0wb0y 在 his comment link 中所示。 .
#include <iostream>
int x = 12;
auto l = [&x](){ return x; };
int main() {
std::cout << l() << std::endl;
}
如果发现 GCC 接受该片段很奇怪,因为 MSVC 正确拒绝它并显示以下错误消息:
error C3480: 'x': a lambda capture variable must be from an enclosing function scope
关于c++ - 你能举个关于这一点的例子吗 : lambda-expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6111617/
我是一名优秀的程序员,十分优秀!