fork download
  1. #include <iostream>
  2. #include <thread>
  3.  
  4. class Foo {
  5. public:
  6. Foo(Foo&& f) {
  7. std::cout << "Constructor Foo&& called: " << this << std::endl;
  8. }
  9. Foo(const Foo& f) {
  10. std::cout << "Constructor const Foo& called: " << this << std::endl;
  11. }
  12. Foo(void) {
  13. std::cout << "Constructor called: " << this << std::endl;
  14. }
  15. ~Foo(void) {
  16. std::cout << "Destructor called: " << this << std::endl;
  17. }
  18. void operator()() const {
  19. std::cout << "Operatior called: " << this << std::endl;
  20. }
  21. };
  22.  
  23. void test_normal(void) {
  24. std::cout << "====> Standard example:" << std::endl;
  25. Foo f;
  26. }
  27.  
  28. void test_thread(void) {
  29. std::cout << "====> Thread example:" << std::endl;
  30. Foo f;
  31. std::thread t(f);
  32. t.detach();
  33. }
  34.  
  35.  
  36. int main(int argc, char **argv)
  37. {
  38. test_normal();
  39. test_thread();
  40.  
  41. for(;;);
  42. }
  43.  
Time limit exceeded #stdin #stdout 5s 11224KB
stdin
Standard input is empty
stdout
====> Standard example:
Constructor called: 0xbfa446bf
Destructor called: 0xbfa446bf
====> Thread example:
Constructor called: 0xbfa446af
Constructor const Foo& called: 0xbfa446ae
Constructor Foo&& called: 0x9a68028
Destructor called: 0xbfa446ae
Destructor called: 0xbfa446af
Operatior called: 0x9a68028
Destructor called: 0x9a68028