Click here to Skip to main content
12,822,179 members (41,443 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ Visual-Studio
Hello friends,
I am a beginner in C++ programming. Today I come accross a new topic: strongly typed enum.I found it in below link.[^]
Then I have googled a lot. But till now I am unable to find out why do we need this? And what is the use of the same?

Let see if,
enum xyz{a, b, c};
/*a = 0, b = 1, c = 2, (Typical C format)*/
Why do we need to write
enum class xyz{a, b, c};

What are we trying to do here?

My most important doubt is how to use it.
Could you pls provide a small example, which will make me understand.

Thanks in advance
Posted 25-Sep-12 1:03am
Legor 25-Sep-12 6:10am
I think the article you posted allready explains it perfectly and it also comes with examples.

Btw. thanks for the article ;)
armagedescu 25-Sep-12 10:38am
I agree. This is good article. And there is very well explained the difference.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Traditional enums have several problems:
1. SCOPE: Enumerations export their enumerators to the surrounding scope. This has two drawbacks. First, it can lead to name clashes, if two enumerators in different enums declared in the same scope have the same name; second, it's not possible to use an enumerator with a fully qualified name, including the enum name.
2. UNDERLYING TYPE: It is not possible to specify the underlying type. It is implementation specific, but it has to be an integral type; it should not be larger than int unless the enumerator value cannot fit an int or unsigned int.
3. CONVERSION TO INT: The values of enumerators implicitly convert to int.

The strongly typed enums do not export their enumerators to the surrounding scope, can have user specified underlying type of an integral type (also added for tranditional enums) and do not convert implicitly to int.

More info you can get here:[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100