Memento Design Pattern in C++

Memento design pattern

Discussion. A memento is an object that stores a snapshot of the
internal state of another object. It can be leveraged to support
multi-level undo of the Command pattern. In this example, before a
command is run against the Number object, Number's current state is
saved in Command's static memento history list, and the command itself
is saved in the static command history list. Undo() simply "pops" the
memento history list and reinstates Number's state from the memento.
Redo() "pops" the command history list. Note that Number's encapsulation is preserved, and Memento is wide open to Number.