fork download
  1. #include <iostream>
  2. using std::cout;
  3. using std::endl;
  4.  
  5. class Test {
  6. public:
  7. Test() { cout << "Default ctor" << endl; }
  8. Test(const Test&) { cout << "Copy ctor" << endl; }
  9. Test(Test&&) { cout << "Move ctor" << endl; }
  10. Test& operator=(const Test&) { cout << "Copy assign" << endl; }
  11. Test& operator=(Test&&) { cout << "Move assign" << endl; }
  12. ~Test() { cout << "Destructor" << endl; }
  13. };
  14.  
  15. Test test_lvalue;
  16.  
  17. void func(bool condition) {
  18. Test test = condition ? test_lvalue : Test();
  19. }
  20.  
  21. int main() {
  22. cout << "Begin main()" << endl;
  23. func(true);
  24. cout << "End main()" << endl;
  25. }
  26.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
Default ctor
Begin main()
Copy ctor
Destructor
End main()
Destructor