如果引用类型的变量在 lambda 中按值捕获,则引用的对象是复制还是通过引用捕获?
有问题的小样本:
#include <iostream>
struct Test {
int a;
};
void testFunc(const Test &test) {
auto a = [=] {
// is 'test' passed to closure object as a copy
// or as a reference?
return test.a;
} ();
std::cout << a;
}
int main() {
Test test{1};
testFunc(test);
}