[英]Cannot capture static member with nested lambda
嵌套lambda函數出現問題,無法看到靜態類成員。 由於我無法理解的原因,Visual Studio 2010給了我一個C2065(未聲明的標識符)。
這是一個突出我的問題的簡單案例:
#include <algorithm>
#include <vector>
using namespace std;
struct foo
{
void do_some()
{
std::vector<int> a;
std::vector<int> b;
for_each( a.begin(), a.end(), [&] ( const int& m )
{
// works
auto j = _i + 1;
for_each( b.begin(), b.end(), [&] ( const int& n )
{
**// doesn't work**
auto k = _i + 1;
} );
} );
}
static int _i;
};
int main(int argc, char* argv[])
{
}
有人知道我在做什么錯嗎?
謝謝,克里斯蒂安
可能是編譯器錯誤(已在VC ++ 2012中修復)。 這有效:
auto k = ::foo::_i + 1;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.