main.cc 722 B

12345678910111213141516171819202122232425
  1. #include <iostream>
  2. #include "originator.hh"
  3. #include "caretaker.hh"
  4. int main(){
  5. Originator* originator = new Originator;
  6. CareTaker* careTaker = new CareTaker;
  7. originator->setState("State #1");
  8. careTaker->add(originator->saveStateToMemento());
  9. originator->setState("State #2");
  10. careTaker->add(originator->saveStateToMemento());
  11. originator->setState("State #3");
  12. std::cout << "Current State: " << originator->getState() << std::endl;
  13. originator->getStateFromMemento(careTaker->get(0));
  14. std::cout << "First save State: " << originator->getState() << std::endl;
  15. originator->getStateFromMemento(careTaker->get(1));
  16. std::cout << "Second saved State: " << originator->getState() << std::endl;
  17. }