I have hit some strange compiler error involving local classes and lambdas. I have narrowed it down to the following example:
int main()
{
class test {
void foo(int bar) {
auto lambda = [=] (int) { return bar; };
}
};
return 0;
}
And VS10 says:
error C2326: ‘void main::test::foo(int)’ : function cannot access ‘bar’
Are there any limitations on using lambdas in local classes or is this a bug in the compiler?
Thanks four your help.
I can confirm that this happens in VS10 only when the class is defined in a function and the lambda accepts a parameter.
No such problems appear in g++.
I believe this is indeed a bug, if you open a defect please link to it here so we can follow up on it (otherwise let me know and I’ll open a defect).