fork(1) download
  1. #include <iostream>
  2.  
  3. bool isTrue()
  4. {
  5. return false;
  6. }
  7.  
  8. class A
  9. {
  10. public:
  11. A()
  12. {
  13. std::cout << "A() called" << std::endl;
  14. }
  15.  
  16. A(const A& ref)
  17. {
  18. std::cout << "A(const A& ref) called" << std::endl;
  19. }
  20.  
  21. A& operator=(const A& ref)
  22. {
  23. std::cout << "A& operator=(const A& ref)" << std::endl; this->member = ref.member;
  24. }
  25.  
  26. A(char* string): member(10)
  27. {
  28. std::cout << "A(char* string) called" << std::endl;
  29. }
  30.  
  31. A(int value): member(2)
  32. {
  33. std::cout << "A(value) called" << std::endl;
  34. }
  35.  
  36. ~A()
  37. {
  38. std::cout <<"destructor called" << std::endl;
  39. }
  40.  
  41. void check()
  42. {
  43. std::cout <<"called the " << member << " constructor" << std::endl;
  44. }
  45.  
  46. int member;
  47. };
  48.  
  49. int main()
  50. {
  51. A a = isTrue() ? A("string") : A(10);
  52. a.check();
  53.  
  54. return 0;
  55. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
A(value) called
called the 2 constructor
destructor called