enum class A
{
type_a,
type_b
};
#define name(a) #a
int main()
{
cout << name(A::type_a) << endl;
}
I can output the 'enum class' variable'name(output 'A::type_a', because it is easier to understand than its value) as above.But if I put the output in a function and use 'A::type_a' as its input variable like below, the 'enum class' variable'name will only output the input variable's name(output 'a' but not 'A::type_a').
void func(A a)
{
cout << name(a) << endl;
}
int main()
{
func(A::type_a);
}
Though I can use 'switch case' to list every name of the enum, but is there any better method that I would not modify the output function even though when I add or delete any item in the enum.