2

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

6
  • 2
    That's what namespaces were invented for. You can wrap the FIRST = 1 in one. Commented Oct 19, 2016 at 8:27
  • 1
    put all of your code in a namespace Commented Oct 19, 2016 at 8:28
  • I can't use namespace as "a.h" file is included in .c files as well. May be we need to look for equivalent of namespace in .c Commented Oct 19, 2016 at 8:33
  • 2
    You don't follow. You use a nemspace in your cxx files, not the header which you can't change. Commented Oct 19, 2016 at 8:34
  • 2
    BTW, you also have an option of placing #include directives inside a namespace.. Commented Oct 19, 2016 at 8:36

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I used for the same problem as mentioned below:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.