I have a problem with a nested lambda function which cannot see a static class member. Visual Studio 2010 gives me a C2065 ( undeclared identifier ) for reasons I cannot understand.
Here is simple case that highlights my problem:
#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[])
{
}
Anyone knows what I'm doing wrong?
Thanks, Christian
Probably a compiler bug (fixed in VC++ 2012). This works: