GCC can't capture 'this' pointer to templated type using init-capture
问题 A templated class can capture its own this pointer in a lambda: template <typename T> class Foo { public: void foo(void) {} auto getCallableFoo(void) { return [this]() { this->foo(); }; } }; This and all other Foo examples can be tested using the following code: int main() { Foo<int> f; auto callable = f.getCallableFoo(); callable(); } However, if instead an init-capture is used, this no longer works with GCC: auto getCallableFoo(void) { return [ptr = this]() { ptr->foo(); }; } Error message