#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 C++, 'const' is a important keyword to avoid bugs. Declaring item of some kind of game, it will be like this. class Item { ...
No comments:
Post a Comment