Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <memory>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. class Bomb;
  6.  
  7. /* Somewhere in your program. Not as a global variable ideally */
  8. std::shared_ptr<Bomb> bomb;
  9.  
  10. class Bomb
  11. {
  12. public:
  13. std::string name;
  14.  
  15. public:
  16. Bomb(std::string name)
  17. {
  18. std::cout << "Bomb()" << std::endl;
  19. this->name = name;
  20. }
  21.  
  22. ~Bomb()
  23. {
  24. std::cout << "~Bomb()" << std::endl;
  25. }
  26.  
  27. void touch()
  28. {
  29. std::cout << name << " is touching the bomb..." << std::endl;
  30.  
  31. /* Simulate everything being exploded! */
  32. bomb.reset();
  33.  
  34. std::cout << "Crickey! The bomb was set off by " << name << std::endl;
  35. }
  36. };
  37.  
  38. int main()
  39. {
  40. bomb = std::make_shared<Bomb>("Teddy");
  41.  
  42. bomb->touch();
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement