Skip to content

Instantly share code, notes, and snippets.

@Aposhian
Created May 9, 2022 16:08
Show Gist options
  • Save Aposhian/4d111fd14ee4c085db05a5ba72dcc283 to your computer and use it in GitHub Desktop.
Save Aposhian/4d111fd14ee4c085db05a5ba72dcc283 to your computer and use it in GitHub Desktop.
Implicit capture of class members when `this` is captured
#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