fork download
  1. #include <iostream>
  2.  
  3. struct Bystander
  4. {
  5. Bystander()
  6. {
  7. std::cout << "Innocent Bystander appears" << std::endl;
  8. }
  9. ~Bystander()
  10. {
  11. std::cout << "Innocent Bystander was shot" << std::endl;
  12. }
  13. };
  14.  
  15. struct Accomplice
  16. {
  17. Bystander const &b;
  18. Accomplice(Bystander const &b)
  19. : b(b)
  20. {
  21. std::cout << "Accomplice received Innocent Bystander" << std::endl;
  22. }
  23. ~Accomplice()
  24. {
  25. std::cout << "Accomplice abandoned Innocent Bystander" << std::endl;
  26. }
  27. };
  28.  
  29. auto Perpetrator(Bystander const &b)
  30. -> Accomplice
  31. {
  32. std::cout << "Committing a Crime by giving Innocent Bystander to Accomplice" << std::endl;
  33. return b;
  34. }
  35.  
  36. int main()
  37. {
  38. std::cout << "About to interact with Perpetrator" << std::endl;
  39. auto a = Perpetrator(Bystander());
  40. std::cout << "Finished interacting with Perpetrator" << std::endl;
  41. }
  42.  
Success #stdin #stdout 0s 3300KB
stdin
Standard input is empty
stdout
About to interact with Perpetrator
Innocent Bystander appears
Committing a Crime by giving Innocent Bystander to Accomplice
Accomplice received Innocent Bystander
Innocent Bystander was shot
Finished interacting with Perpetrator
Accomplice abandoned Innocent Bystander