fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Light
  5. {
  6. Light() { cout << "Light()"<<endl; }
  7. Light(const Light&) { cout << "Light(const Light&)"<<endl; }
  8. ~Light() { cout << "~Light()"<<endl; }
  9. };
  10.  
  11. struct Heavy
  12. {
  13. Heavy() { cout << "Heavy()"<<endl; }
  14. Heavy(const Heavy&) { cout << "Heavy(const Heavy&)"<<endl; }
  15. //Heavy(const Light&) { cout << "Heavy(const Light&)"<<endl; }
  16. ~Heavy() { cout << "~Heavy()"<<endl; }
  17.  
  18. operator Light() { cout << "operator Light()"<<endl; Light l; return l; }
  19. };
  20.  
  21. Light ternary(Heavy* h)
  22. {
  23. cout << "ternary"<<endl;
  24. return h ? *h : Light();
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30. Heavy h;
  31. Light l = ternary(&h);
  32.  
  33. cout << "return"<<endl;
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 3100KB
stdin
Standard input is empty
stdout
Heavy()
ternary
operator Light()
Light()
return
~Light()
~Heavy()