Created
October 23, 2015 16:12
-
-
Save goyusia/58a075f6cd4590bbac99 to your computer and use it in GitHub Desktop.
new history teaching
This file contains hidden or 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
| main: | |
| make current; \ | |
| make dystopia | |
| current: new_history_teaching.cpp | |
| rm -rf a.out | |
| clang++ $^ -W -Wall | |
| ./a.out | |
| dystopia: new_history_teaching.cpp | |
| rm -rf a.out | |
| clang++ $^ -W -Wall -DNEW_HISTORY_TEACHING | |
| ./a.out | |
| clean: | |
| rm -rf a.out *.o |
This file contains hidden or 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
| /* | |
| Usage | |
| $ make current | |
| new_history_teaching.cpp:23:9: error: no viable overloaded operator[] for type 'const history_t' (aka 'const map<year_t, event_t>') | |
| history[1972] = "nothing"; | |
| ... | |
| (compile error) | |
| $ make dystopia | |
| what happend in 1972 : nothing | |
| */ | |
| #include <map> | |
| #include <string> | |
| #include <cstdio> | |
| #if NEW_HISTORY_TEACHING | |
| #define const | |
| #endif | |
| typedef int year_t; | |
| typedef std::string event_t; | |
| typedef std::map<year_t, event_t> history_t; | |
| const history_t create_original_history() | |
| { | |
| history_t h; | |
| h[1972] = "유신"; | |
| return h; | |
| } | |
| int main() | |
| { | |
| const history_t history = create_original_history(); | |
| history[1972] = "nothing"; | |
| printf("what happend in 1972 : %s\n", history[1972].data()); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment