Thread: accessing enum members

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    222

    accessing enum members

    I'm trying to access the enum as described below:

    Code:
    enum SomeEnum
    {
          memberA = ...;
          memberB = ...;
    // more members
    };
    I'm trying to use one of the members of the enum as shown in an example function call here:
    Code:
          somefunc(memberA);
    Basically, how would I access any member of the enum properly?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You don't access the members of an enum.

    You see, an enum is a type of variable that can be assigned to one of many different values. For example:
    Code:
    enum fruit {
        apple,
        pear
    };
    
    fruit favourite = apple;
    
    if(favourite == pear) {
        /* ... */
    }
    etc.

    Defining an enum makes the values of the enum visible, like constants or #defines, and those values can be assigned to variable of the enum's type.

    [edit] http://www.cprogramming.com/tutorial/enum.html [/edit]

    [edit] If you're looking for a construct where you can access the members, look up structs, classes, or perhaps unions (but probably not). [/edit]
    Last edited by dwks; 07-24-2008 at 03:08 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing private Data members
    By Emeighty in forum C++ Programming
    Replies: 17
    Last Post: 08-14-2008, 11:16 PM
  2. Accessing members of a class within a template
    By chadwickstein in forum C++ Programming
    Replies: 10
    Last Post: 10-03-2006, 09:47 AM
  3. accessing members in nested structs
    By amidstTheAshes in forum C Programming
    Replies: 2
    Last Post: 03-23-2005, 02:00 PM
  4. Accessing private data members
    By maloy in forum C++ Programming
    Replies: 11
    Last Post: 10-04-2002, 02:48 PM
  5. Accessing structure members
    By foniks munkee in forum C Programming
    Replies: 18
    Last Post: 02-13-2002, 03:06 PM