Consider the following code:
class A { public: void foo() { auto functor = [this]() { A * a = this; auto functor = [a]() // The compiler won't accept "this" instead of "a" { a->bar(); }; }; } void bar() {} };
In VC2010, using this instead of a leads to compilation errors. Among other things:
1>main.cpp(20): error C3480: '`anonymous-namespace'::<lambda0>::__this': a lambda capture variable must be from an enclosing function scope 1>main.cpp(22): error C3493: 'this' cannot be implicitly captured because no default capture mode has been specified
What? I do not understand. Does this mean that he does not know whether to use the link or copy it? When trying to use &this to force binding, it also says:
1>main.cpp(20): error C3496: 'this' is always captured by value: '&' ignored
Temporary is not something that annoys, but for the sake of curiosity, is there a way to get rid of it? What happens when this provided lambda?
c ++ lambda this c ++ 11
Gabriel
source share