Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <memory>
- #include <iostream>
- #include <string>
- class Bomb;
- /* Somewhere in your program. Not as a global variable ideally */
- std::shared_ptr<Bomb> bomb;
- class Bomb
- {
- public:
- std::string name;
- public:
- Bomb(std::string name)
- {
- std::cout << "Bomb()" << std::endl;
- this->name = name;
- }
- ~Bomb()
- {
- std::cout << "~Bomb()" << std::endl;
- }
- void touch()
- {
- std::cout << name << " is touching the bomb..." << std::endl;
- /* Simulate everything being exploded! */
- bomb.reset();
- std::cout << "Crickey! The bomb was set off by " << name << std::endl;
- }
- };
- int main()
- {
- bomb = std::make_shared<Bomb>("Teddy");
- bomb->touch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement