#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.
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:
Post Comments (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...
- 
std::function is a class for 'function object'. This is powerful way to represent predicator. Let's see how to use it. Firs...
 - 
Copy constructor is used to copy instance. We need to declare copy constructer when simple memory copying is undesirable. For example, le...
 - 
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 ...
 
No comments:
Post a Comment