K P
K P

Reputation: 49

How to avoid duplicate enum value from other .cxx

I have a large number of files in my code base. I am trying to compile my code base using other library that has one file a.h. I am running into compilation problem if I include say a.h file in my code base that has already defined some of the values with same enum as defined in a.h. For example:

in "a.h" header file

typedef enum mylist_s
{
   FIRST,
   SECOND,
   THIRD,
   FOUR,
   ::::::
} mylist_e;

in other .cxx file as shown below (if it has definition same as defined in mylist)

static const char FIRST = 1;

I understand there is a definition of same variable again. I don't want to change my code base with new variable. Also since a.h is include in both .c and .cxx file I can not use namespace to encapsulate it with other name.

I also don't want to change name in a.h file. Is there an any other way I can handle this situation without changing enum value name.

Thanks in advance

Upvotes: 2

Views: 476

Answers (2)

K P
K P

Reputation: 49

I used for the same problem as mentioned below:

struct mylist_s
{
    enum Type
    {
        FIRST,
        SECOND,
        THIRD,
        FOUR
    };
};
typedef mylist_s::Type mylist_e;

Upvotes: 0

user9478968
user9478968

Reputation:

C++ namepsace's are to prevent name collisions from occurring.

Defining all of your implementation code inside of a custom namespace should resolve the issue.

Upvotes: 1

Related Questions