Last active
February 2, 2021 19:50
-
-
Save Xenakios/e30a7c0be13808802a4d1fc5b930a8bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Undoable | |
{ | |
public: | |
Undoable() {} | |
void setString(std::string str) | |
{ | |
if (str.find("🍺") != std::string::npos) | |
{ | |
std::cout << "No beer tonight! String not set.\n"; | |
return; | |
} | |
oldString = currentString; | |
currentString = str; | |
} | |
std::string getString() const | |
{ | |
return currentString; | |
} | |
void undo() | |
{ | |
setString(oldString); | |
} | |
private: | |
std::string currentString; | |
std::string oldString; | |
}; | |
void test_undoclass() | |
{ | |
Undoable u; | |
u.setString("bar"); | |
u.setString("foo"); | |
std::cout << u.getString() << "\n"; | |
u.undo(); | |
std::cout << u.getString() << "\n"; | |
u.undo(); | |
std::cout << u.getString() << "\n"; | |
u.setString("Getting some 🍺 tonight!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment