fork download
  1. #include <cstdlib>
  2. #include <thread>
  3. #include <chrono>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7. using namespace std::literals;
  8.  
  9. struct A
  10. {
  11. int n_ = 0;
  12. A(int n) : n_(n) { cout << "A:" << n_ << endl; }
  13. ~A() { cout << "~A:" << n_ << endl; }
  14. };
  15.  
  16. A a1(1);
  17.  
  18. int main()
  19. {
  20. std::thread t([]()
  21. {
  22. static A a2(2);
  23. thread_local A a3(3);
  24. std::this_thread::sleep_for(4s);
  25. });
  26.  
  27. static A a4(4);
  28. thread_local A a5(5);
  29.  
  30. std::this_thread::sleep_for(2s);
  31. t();
  32. std::exit(0);
  33. }
Compilation error #stdin compilation error #stdout 0s 83648KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:31:7: error: no match for call to ‘(std::thread) ()’
     t();
       ^
stdout
Standard output is empty