Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8799363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:18:15+00:00 2026-06-14T00:18:15+00:00

What is the rationale behind unconditionally requiring explicit scope resolution in strongly typed enumerations?

  • 0

What is the rationale behind unconditionally requiring explicit scope resolution in strongly typed enumerations?

N2347 explains the difference to old-fashion enumerations which are absence of implicit conversion, ability to specify storage type, and no injection of names in the surrounding scope (as in C++03, which has that as a heritage of C).

In other words, writing enum E1 { a, b, c}; as in C++03 is similar to writing

const int a = 1; const int b = 2; const int c = 3;

whereas enum E1 class { a, b, c}; as in C++11 is much more similar to something like

namespace E1 { const int a = 1; const int b = 2; const int c = 3; }

(without introducing a namespace, and with defining an enum type in either case).

Now, I generally don’t understand where there is an ambiguity, assuming one has for example code like the following (which won’t compile):

enum class E1 { a, b, c };
enum class E2 { a, b, c }; // allowed now

void foo(E1 e) { ... }
void bar(E2 e) { ... }
void baz(int e) { ... }

foo(a);   // not ambigious: E1 expected, nothing but E1::a possible
bar(a);   // not ambigious: E2 expected, nothing but E2::a possible
baz(a);   // not ambigious: illegal - no name `a` in global scope

E1 x = a; // not ambigious: E1 expected, nothing but E1::a possible

I welcome (optional) explicit scope resolution in some cases to point out what’s going on, but I do not understand why C++11 requires explicit scope resolution, even when there is no possible way of interpreting code in another way.

It would in my opinion be reasonable to expect that for example void foo(E1 e); has a meaning much more like void foo(using enum E1; E1 e); (my syntax is of course totally wrong, but you get the idea).

Taking the “classic” example of Color and Alertthat is also in N2347, one has red alert, and the color red, which may be different numeric constants, too. Without strong type guarantees, it is conceivable that one ends up using the alert numeric constant when one really wants to e.g. set a red color on a display. Or, with integer conversions and a lax function declaration, it is conceivable that someone ends up using something like yellow|red to get orange.

None of that is possible, so what exactly are we defending against?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:18:16+00:00Added an answer on June 14, 2026 at 12:18 am

    foo(a); // not ambigious: E1 expected, nothing but E1::a possible

    The type of the expression must be known. And since the use of a as a free-standing expression is ambiguous, the use of a anywhere is ambiguous.

    You don’t want expressions to change their meaning depending on the context they’re used in. 1 + 1 always means the same thing. 1 + t always means the same thing if you use the same t. Similarly, a should always mean the same thing no matter where it is used.

    The only thing in C++ that allow for the deduction of the source type based on the context in which it is used is uniform initialization. And the standard explicitly states that a “braced-init-list” is not an expression. a is an expression, so it follows the expression rules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What's the rationale behind curried functions in Scala? I have two difference
I am trying to understand the rationale behind such a design. I skimmed through
Possible Duplicate: What is the rationale behind having companion objects in Scala? Thanks for
What's the rationale behind dropping the frame pointer on 64-bit architectures by default? I'm
What's the rationale behind not allowing * in relative imports? e.g. from ..new_tool import
What is the rationale behind the advocated use of the for i in xrange(...)
What was the rationale behind introducing protected access specifier in C++. An example would
What is the rationale behind the design decision to have separate namespaces for values
Can someone explain me the rationale behind having these two functions, instead of just
I am curious about the rationale behind noexcept in the C++0x FCD . throw(X)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.