- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
当一个 lambda 函数在 C
类的友元函数 F
中声明时,该 lambda 函数是否可以访问 C
私有(private)成员(member)?具体来说,标准允许吗?
最佳答案
C++11 §[expr.prim.lambda] 5.1.2/3:
The type of the lambda-expression (which is also the type of the closure object) is a unique, unnamed non-union class type — called the closure type — whose properties are described below. This class type is not an aggregate (8.5.1). The closure type is declared in the smallest block scope, class scope, or namespace scope that contains the corresponding lambda-expression. ...
由于闭包类型是在友元函数中声明的,因此根据 §[class.local] 9.8/1 将具有相同的访问权限:
A class can be declared within a function definition; such a class is called a local class. The name of a local class is local to its enclosing scope. The local class is in the scope of the enclosing scope, and has the same access to names outside the function as does the enclosing function. ...
关于C++ lambda 友元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23834845/
我是一名优秀的程序员,十分优秀!