fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. class B
  6. {
  7. public:
  8. B ();
  9. B (const B& other);
  10. B (B &&other);
  11. ~B ();
  12.  
  13. private:
  14. int id;
  15. static int current;
  16.  
  17. friend std::ostream &operator<< (std::ostream &, const B&);
  18. };
  19.  
  20. int B::current = 0;
  21.  
  22. std::ostream &operator<< (std::ostream &out, const B& b)
  23. {
  24. return out << "B" << b.id;
  25. }
  26.  
  27. B::B (B &&other) : id (current++)
  28. {
  29. std::cout << other << "=>" << *this << "*" << std::endl;
  30. }
  31.  
  32. B::B (const B& other) : id (current++)
  33. {
  34. std::cout << *this << "(" << other << ")" << std::endl;
  35. }
  36.  
  37. B::B () : id (current++)
  38. {
  39. std::cout << *this << "*" << std::endl;;
  40. }
  41.  
  42. B::~B ()
  43. {
  44. std::cout << *this << "~" << std::endl;
  45. }
  46.  
  47. B func (bool flag)
  48. {
  49. B t, f;
  50.  
  51. std::cout << "func(" << std::boolalpha << flag << ")" << std::endl;
  52.  
  53. return flag ? t : f;
  54. }
  55.  
  56. int main ()
  57. {
  58. B b1 = func (true);
  59. std::cout << "main" << std::endl;
  60.  
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0s 2900KB
stdin
Standard input is empty
stdout
B0*
B1*
func(true)
B2(B0)
B1~
B0~
main
B2~