#include <iostream>
#include <string>
int main() {
int x = 42;
const std::string s = "now";
auto f = [&r = x, c = "text", s = s]() mutable {
r = 100500;
s[0] = 'w';
std::cout << s << "\n";
};
std::cout << x << "\n";
f();
std::cout << x << "\n";
std::cout << s << "\n";
}
存在这种可能性,至少在 lambda 函数捕获领域(c++14)。在此上下文中缺少类型的处理方式与
auto在本地上下文中使用类型声明的变量相同。例子:这里
r有类型int&,c-const char*,s(在 lambda 体内) -std::string。Вывод: