Thread: Questions about the enum keyword

  1. #1
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Question Questions about the enum keyword

    Hello, I was wondering if the enum keyword is affected by class/struct access specifiers (public, protected, and private)?
    Also, I need to know if its possible to "nest" one enum type inside another enum type.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Programmer_P View Post
    Hello, I was wondering if the enum keyword is affected by class/struct access specifiers (public, protected, and private)?
    Also, I need to know if its possible to "nest" one enum type inside another enum type.
    If you declare an enum inside a class, then its visibility is controlled just like any other member. Outside of a class, it is always visible.

    As far as nesting, I'm not sure exactly what you mean.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    As far as nesting, I'm not sure exactly what you mean.
    I think he's referring to nesting enums in a manner similar to how you can nest classes in C#.

    I need to know if its possible to "nest" one enum type inside another enum type.
    Enums are not nestable in C++.
    My Website

    "Circular logic is good because it is."

  4. #4
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by brewbuck View Post
    If you declare an enum inside a class, then its visibility is controlled just like any other member. Outside of a class, it is always visible.
    Thanks.
    As far as nesting, I'm not sure exactly what you mean.
    I mean like this...

    Code:
    class VEHICLE {
    
      enum CAR {
            //general car types here
            enum BMW {
                    //only BMW model cars here
            }
      }
    }

  5. #5
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Thumbs up

    Quote Originally Posted by DavidP View Post
    Enums are not nestable in C++.
    Thanks David.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic questions about enum
    By George2 in forum C# Programming
    Replies: 3
    Last Post: 05-15-2008, 05:58 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Conflicting enum issue
    By 7force in forum C Programming
    Replies: 1
    Last Post: 07-05-2006, 03:51 AM
  4. a few keyword questions and %i/%d
    By ytaipsw in forum C Programming
    Replies: 7
    Last Post: 05-21-2006, 07:06 PM
  5. Stacks and enum questions
    By joenching in forum C++ Programming
    Replies: 10
    Last Post: 04-25-2005, 06:39 PM