How to handle a class name conflict when porting old code?

后端 未结 5 1605
情话喂你
情话喂你 2021-01-05 23:04

I\'m trying to port an old library (that doesn\'t use namespaces as far as I can tell) to modern compilers. One of my targets can\'t tell the difference between System::TObj

相关标签:
5条回答
  • 2021-01-05 23:12

    I have used the following in the past while encapsulating a third party header file containing classes colliding with the code:

    #ifdef Symbol
    #undef Symbol
    #define Symbol ThirdPartySymbol
    #endif
    #include <third_party_header.h>
    #undef Symbol
    

    This way, "Symbol" in the header was prefixed by ThirdParty and this was not colliding with my code.

    0 讨论(0)
  • 2021-01-05 23:13

    You can do as Dib suggested, with a slight modification:

    // In a wrapper header, eg: include_oldlib.h...
    
    namespace oldlib
    {
       #include "oldlib.h"
    };
    
    #ifndef DONT_AUTO_INCLUDE_OLD_NAMESPACE
    using namespace oldlib;
    #endif
    

    This allows you to #define the exclusion in only the files where you're getting conflicts, and use all the symbols as global symbols otherwise.

    0 讨论(0)
  • 2021-01-05 23:14

    If you have the source to the library, maybe include a header file at the top of each source where that header file has only:

    #define TObject TMadeUpNameObject
    
    0 讨论(0)
  • 2021-01-05 23:30

    You could make a wrapper for all the old functions and package them up into a DLL or static library.

    0 讨论(0)
  • 2021-01-05 23:33

    Try this:

    namespace oldlib
    {
       #inclcude "oldlib.h"
    };
    
    0 讨论(0)
提交回复
热议问题