c++ - Can inline lambda initializer capture 'this' pointer? -
can inline member initialization lambda capture , use this pointer?
struct a{   int = 42;   int b = [this](){     return this->a * 4;   }(); }; is valid c++11 code (according specification) or gcc extension?
if valid, why have use this-> when referring member a?
is valid c++11 code?
no. lambdas in block scope can have capture lists:
c++11 5.1.2/9 lambda-expression smallest enclosing scope block scope local lambda expression; other lambda-expression shall not have capture-list in lambda-introducer.
so seems gcc extension. (as noted in comments, open issue, might become standard 1 day.)
why have use
this->while referring member a?
you don't, @ least version of gcc i'm using: http://ideone.com/k857vc.
Comments
Post a Comment