#include <iostream>
#include <functional>
#include <thread>
#include <vector>
class t {
public:
int m = 1;
std::function<void()> f;
t() {
f = [this]() {
std::cout << "2: " << this << std::endl;
std::cout << m << std::endl;
};
}
void operator()() {
m = 2;
std::cout << "1: " << this << std::endl;
f(); // print 1
}
};
int main() {
std::vector<std::thread> threads;
for(int i = 1; i <= 1; i++) {
threads.emplace_back(t());
}
for (auto &thread : threads) {
thread.join();
}
}