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 8514385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:51:11+00:00 2026-06-11T04:51:11+00:00

I have a set of enum values defined in the Foo class (below). namespace

  • 0

I have a set of enum values defined in the “Foo” class (below).

namespace Fii
{
    class Foo 
    {
        struct Bar
        {
            enum Baz
            {
                BAZ1,
                BAZ2, 
                BAZ3
            };
        };
    };
};

I am using a struct to reduce the scope of Baz enum values as well as show there are a group of related values.

My objective is to assign a value from an enum type to a variable. Using the class definition above, one can do this:

Fii::Foo::Bar::Baz myValue = Fii::Foo::Bar::BAZ1 (Works in both C++98 and C++11)

However, I feel that:

  • At first glance, myValue seems to be initialized as a Fii::Foo::Bar but this is just because enum are a hack to group related constants in the parent (Bar in this case)

To improve readiness, I I re-factored the code to:

namespace Fii
{
    class Foo 
    {
        enum Baz
        {
            BAZ1,
            BAZ2, 
            BAZ3
        };
    };
};

Using this new class definition, one can do this:

Fii::Foo::Baz myValue = Fii::Foo::Baz::BAZ1 (Works in C++11 only)
Fii::Foo::Baz myValue = Fii::Foo::BAZ1 (Should work on C++98 and C++11 - not tested)

Q1) Why is Fii::Foo::Bar::Baz myValue = Fii::Foo::Baz::BAZ1 only working on C++11 ?

Q2) In C++98, is there a way to write Fii::Foo::Baz myValue = Fii::Foo::Baz::BAZ1 ? You are allowed to make any changes you like in the class definition.

Environment:
– Clang compiler with C++11 support
– Xcode 4
– Mac OS OS 10.8

  • 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-11T04:51:13+00:00Added an answer on June 11, 2026 at 4:51 am

    juanchopanza’s answer’s valid for Q1…

    Q2: In C++98, is there a way to write Fii::Foo::Baz myValue = Fii::Foo::Baz::BAZ1 ? You are allowed to make any changes you like in the class definition.

    Something like:

    namespace Fii
    {
        class Foo
        {
            class Baz
            {
              public:
                enum E { BAZ1, BAZ2, BAZ3 };
                Baz(E e) : e_(e) { }
                operator const E() const { return e_; }
              private:
                E e_;
            };
        };
    }
    

    Explanation: for Fii::Foo::Baz::BAZ1 to be a valid reference to an enumeration in C++03, Baz must be a namespace or class/struct/union. But, we’re trying to make it seem as if Baz itself is the enumeration type, with BAZ1 being one of the available values. To do that, we must make Baz a user-defined-type (a class/struct) capable of storing any of the enumerations declared within its scope. Therefore, we add a data member to record the current value, a constructor to set the value, an operator to expose the enumeration value implicitly so you’d don’t need to code explicit references to e_ everywhere in the code using Baz objects or call some get() const function.

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

Sidebar

Related Questions

I'm attempting to have a combo-box display a pre-defined set of values - in
I have the class defined as below public partial class School { public StudentDetails
how do i switch on an enum which have the flags attribute set (or
I have the following property defined. MyLibrary.PumpSignal is an enum as follows: Public Enum
Lets say I have this enum defined (from Apple's UIKit framework): typedef enum {
I have 2 classes and an Enum. One class is a wrapper for the
I have an array whose indices map back to Enum values. I would like
I have an Enumeration whitch values I want to aliment to a Combobox. Enum
I have defined a dependency property that uses an enum to update the background
I have a class that has an enum type indicating whether the message type

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.