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

  • Home
  • SEARCH
  • 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 115307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:59:54+00:00 2026-05-11T02:59:54+00:00

Often, one needs several enumerated types together. Sometimes, one has a name clash. Two

  • 0

Often, one needs several enumerated types together. Sometimes, one has a name clash. Two solutions to this come to mind: use a namespace, or use ‘larger’ enum element names. Still, the namespace solution has two possible implementations: a dummy class with nested enum, or a full blown namespace.

I’m looking for pros and cons of all three approaches.

Example:

// oft seen hand-crafted name clash solution enum eColors { cRed, cColorBlue, cGreen, cYellow, cColorsEnd }; enum eFeelings { cAngry, cFeelingBlue, cHappy, cFeelingsEnd }; void setPenColor( const eColors c ) {     switch (c) {         default: assert(false);         break; case cRed: //...         break; case cColorBlue: //...         //...     }  }   // (ab)using a class as a namespace class Colors { enum e { cRed, cBlue, cGreen, cYellow, cEnd }; }; class Feelings { enum e { cAngry, cBlue, cHappy, cEnd }; }; void setPenColor( const Colors::e c ) {     switch (c) {         default: assert(false);         break; case Colors::cRed: //...         break; case Colors::cBlue: //...         //...     }  }    // a real namespace?  namespace Colors { enum e { cRed, cBlue, cGreen, cYellow, cEnd }; };  namespace Feelings { enum e { cAngry, cBlue, cHappy, cEnd }; };  void setPenColor( const Colors::e c ) {     switch (c) {         default: assert(false);         break; case Colors::cRed: //...         break; case Colors::cBlue: //...         //...     }   } 
  • 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. 2026-05-11T02:59:55+00:00Added an answer on May 11, 2026 at 2:59 am

    Original C++03 answer:

    The benefit from a namespace (over a class) is that you can use using declarations when you want.

    The problem with using a namespace is that namespaces can be expanded elsewhere in the code. In a large project, you would not be guaranteed that two distinct enums don’t both think they are called eFeelings

    For simpler-looking code, I use a struct, as you presumably want the contents to be public.

    If you’re doing any of these practices, you are ahead of the curve and probably don’t need to scrutinize this further.

    Newer, C++11 advice:

    If you are using C++11 or later, enum class will implicitly scope the enum values within the enum’s name.

    With enum class you will lose implicit conversions and comparisons to integer types, but in practice that may help you discover ambiguous or buggy code.

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

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer /* We include the following to get the prototypes for:… May 11, 2026 at 11:00 am
  • added an answer Yes. Set the text property to '*' and the ErrorMessage… May 11, 2026 at 11:00 am
  • added an answer It depends on your compiler settings. However, by default, anything… May 11, 2026 at 11:00 am

Related Questions

Often, one needs several enumerated types together. Sometimes, one has a name clash. Two
I often run into the problem that I have one stream full of data
Often while editing config files, I'll open one with vi and then when I
Quite often one has to encode an big (e.g. 128 or 160 bits) number
The problem: I often have to update two or more repositories: One for the
I seem to often find myself wanting to store data of more than one
One thing I've started doing more often recently is retrieving some data at the
How does one design loosely-coupled systems which may often require data from each-other but
One of the problems I often run into, is that I will include '
Encoding issues are among the one topic that have bitten me most often during

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.