Questions about the enum keyword

This is a discussion on Questions about the enum keyword within the C++ Programming forums, part of the General Programming Boards category; Hello, I was wondering if the enum keyword is affected by class/struct access specifiers (public, protected, and private)? Also, I ...

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,269
    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,738
    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, 06: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, 06:36 AM
  3. Conflicting enum issue
    By 7force in forum C Programming
    Replies: 1
    Last Post: 07-05-2006, 04:51 AM
  4. a few keyword questions and %i/%d
    By ytaipsw in forum C Programming
    Replies: 7
    Last Post: 05-21-2006, 08:06 PM
  5. Stacks and enum questions
    By joenching in forum C++ Programming
    Replies: 10
    Last Post: 04-25-2005, 07:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21