c++ - X-Macros Redefinition -
When I include "xmacro.h" in the header file which is used by multiple header files, then I Error:
Error LNK2005: "char const * * iD_Strings" (? ID_Strings @@ 3PAPBDA) is already defined in header_file.obj
1 .// "Xmacro.h" 2. 3. (1) defined macro generated code 4. 5. #ifndef XMACRO_H 6. # Defined XMACRO_H 7. 8. #DIFINE GENERATE_IDS \ 9.X (_Name, "/ name") \ 10x (_ID, "/ ID ") 11. 12. 12. (2) Define X-Macro to generate members of ENUM 14. 14. 14. Define the X (ID, IDString) ID, 15 NIUI ID 16. ID_LOWERBOUND = -1, 18. GENERATE_IDS 19. NUM_IDS 20.}; 21. #undef x 22. 23. // (3) Define X-Macro to generate string names. 25. #x (id, idstrings) idstrings, 26 Const four * iD_Strings [] = 27. {28 GENERATE_IDS 29. NULL 30.}; 31. #undef x 32. 33. #endif
This creates an error while defining an X-macro to generate string names on line 23. I will use a macro without defining it
Definition the iD_Strings
. When you include it from various source files, it is sometimes linked, the result can be in a conflict, even if the definitions are the same.
You can declare the iD_Strings
as the static
(the path) or wrap it in anonymously to solve this problem Namespace (C ++ way) for
Comments
Post a Comment