Possible Duplicate:
lambdas require capturing 'this' to call static member function?
I want to use c++11 lambda in a non-static member function and call a static member function of same class:
class A {
static void a() {}
public:
void x() {
[] () { A::a(); }();
}
};
But gcc4.6 and gcc4.7 both got an error:
error: ‘this’ was not captured for this lambda function
Why does lambda need ‘this’ since ‘a’ is a static member function.
And if ‘x’ is static or ‘a’ is static member function of other class, ‘this’ is not necessary, why?
This compiles fine with clang 3.2. Also, there is no reason why this shouldn’t be compile. This is a bug in GCC as per the notes. This ought to be fixed in 4.7.1. Note that gcc started early but has lagged behind clang in supporting some of the C++11 features.
Edit: There is a similar SO question which you may want to check out.