#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...
-
In most of game programs, It is the common problem that how to organize classes. We have a class Player, Enemy, Obstacle, Bullet, ...and t...
-
In previous post , We learn meanings of Class, Methods in C++,which is the set of data and how to process that. And see the simple video g...
-
Copy constructor is used to copy instance. We need to declare copy constructer when simple memory copying is undesirable. For example, le...
No comments:
Post a Comment