#define ENM \ E(AAA)\ E(BBB) #define E(x) x, enum { ENM }; #undef E #define E(x) #x, const char* strs[] = { ENM }; #undef E int main() { cout << AAA << endl; // 0 cout << strs[AAA] << endl; // AAA return 0; }
Happy Programming! I am a game programmer and this blog introduces technical issues, and my daily programming struggle against various jobs.
Showing posts with label enum. Show all posts
Showing posts with label enum. Show all posts
Wednesday, August 23, 2017
Enum with string
If you need enums and strings that are equivalent as that names, You can declare like this.
Subscribe to:
Posts (Atom)
It's magic! std::bind
'std::bind' is a powerful helper for working around 'std::function'. 'std::bind' makes a instance of 'std::fun...
-
In most of games, the game status will change in every moment, even if there is no user input. So game program must have game loop, which ...
-
In C++, 'const' is a important keyword to avoid bugs. Declaring item of some kind of game, it will be like this. class Item { ...
-
std::function is a class for 'function object'. This is powerful way to represent predicator. Let's see how to use it. Firs...