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

北城余情 提交于 2019-11-30 21:18:34

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.

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

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

Try this:

namespace oldlib
{
   #inclcude "oldlib.h"
};

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!