fork download
  1. #include <iostream>
  2. #include <future>
  3. #include <unistd.h>
  4.  
  5. using namespace std;
  6.  
  7. struct theClass {
  8.  
  9. void member() {
  10. cout << "this: " << (void*)this << "\n";
  11. cout << "this_thread id: " << this_thread::get_id() << "\n";
  12.  
  13. theClass* that = this;
  14.  
  15. async([that]() {
  16. usleep(100);
  17.  
  18. cout << "that: " << (void*)that << "\n";
  19. cout << "that_thread id: " << this_thread::get_id() << "\n";
  20. });
  21. }
  22.  
  23. };
  24.  
  25. void temp() {
  26. theClass().member();
  27. }
  28.  
  29. int main() {
  30. temp();
  31. return 0;
  32. }
Success #stdin #stdout 0s 18128KB
stdin
Standard input is empty
stdout
this: 0x7ffce39c2a6f
this_thread id: 47384514750784
that: 0x7ffce39c2a6f
that_thread id: 47384536184576