Created
May 9, 2022 16:08
-
-
Save Aposhian/4d111fd14ee4c085db05a5ba72dcc283 to your computer and use it in GitHub Desktop.
Implicit capture of class members when `this` is captured
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class MyClass { | |
public: | |
void do_stuff() { | |
auto fn = [this]() { | |
do_more_stuff(); | |
}; | |
fn(); | |
} | |
private: | |
void do_more_stuff() { | |
std::cout << "do_more_stuff" << std::endl; | |
} | |
}; | |
int main() { | |
MyClass a; | |
a.do_stuff(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment