使用C++ 0x时,如何在lambda内使用lambda时捕获变量?例如:C++中的闭包和嵌套lambdas 0x
std::vector<int> c1;
int v = 10; <--- I want to capture this variable
std::for_each(
c1.begin(),
c1.end(),
[v](int num) <--- This is fine...
{
std::vector<int> c2;
std::for_each(
c2.begin(),
c2.end(),
[v](int num) <--- error on this line, how do I recapture v?
{
// Do something
});
});
我猜分配在第一关闭可能会帮助该变量。 – 2010-05-23 12:34:14
以上在gcc4.5上很好 - 你使用VC10吗? – 2010-05-23 12:47:26
是的,VC10。我会把它报告给微软。 – DanDan 2010-05-23 12:51:28