Thread: name conflicts in enum

  1. #1
    Registered User
    Join Date
    May 2006

    name conflicts in enum

    Hello everyone,

    Suppose I have two enums which has an item with the same names -- but different values,

    enum foo {
              NAME = 100;
    enum goo {
              NAME = 200;
    Are there any ways to specify whether I need to access NAME in foo or NAME in goo?

    thanks in advance,

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Unless they are in separate header files that are unrelated, or you are using C++, you can't.

    In C++, you can use foo::NAME and goo::NAME [I think!]

    It's a bad idea to use the same enum name for different values. Renaming at least one so that it's got unique names would be much better.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Hence why you usually name the members of the enum prefixed with the name of the enum, for example.
    enum foo {
              FOO_NAME = 100;
    enum goo {
              GOO_NAME = 200;
    Or even, G_NAME and F_NAME.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic question on enum
    By MasterM in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2009, 09:16 PM
  2. enum [tag] [: type] Is this non-standard?
    By HyperShadow in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2007, 10:29 PM
  3. enum switchcase and windows message q
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2006, 01:16 PM
  4. Conflicting enum issue
    By 7force in forum C Programming
    Replies: 1
    Last Post: 07-05-2006, 03:51 AM
  5. Switch case and enum help
    By SomeCrazyGuy in forum C++ Programming
    Replies: 9
    Last Post: 04-21-2005, 08:53 PM