typeid of enumerator

hello

i am reading about enumeration and i was trying this example using "Visual C++ 2012":
1
2
enum Suit {Clubs, Diamonds, Hearts, Spades};
cout<<typeid(Suit::Diamonds).name()<<endl;

i though that it will give me int as output but instead i received this:
?AW4Suit@?1?main@

So i tried other example:
1
2
enum  Suit {Clubs, Diamonds, Hearts, Spades};
cout<<typeid(Suit).name()<<endl;

and i even used enum class :
1
2
enum class Suit {Clubs, Diamonds, Hearts, Spades};
cout<<typeid(Suit::Diamonds).name()<<endl;

they all gave me the same output:
?AW4Suit@?1?main@

can anyone explain why, please?
Last edited on
In both cases, an enum is actually a unique type, not just a fancy way to crate a bunch of integer constants. With the regular old deprecated "enum", it is implicitly convertible to and from an int, which is why in old code you often see it used that way. It isn't actually an int, but it can be converted to and from an int without explicitly casting.
Last edited on
thanks L B for your reply.
I wonder what would happen if you did this:
1
2
3
enum Suit : char
{Clubs, Diamonds, Hearts, Spades};
cout<<typeid(Suit::Diamonds).name()<<endl;
Topic archived. No new replies allowed.