移植旧代码时如何处理类名冲突?
我试图将一个旧的库(尽管我可以告诉使用命名空间)移植到现代编译器。我的一个目标不能告诉System :: TObject和:: TObject(没有命名空间)之间的区别。 System :: TObject是编译器原生的。
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::TObject and ::TObject (without a namespace). System::TObject is native to the compiler.
我尝试过一个using指令,即使用:: TObject;
I've tried a using directive, i.e. using ::TObject;
但不是这样的。
显而易见的解决方案是将所有原始库包装在命名空间中,然后通过name-调用它,避免模糊性。但是这是最聪明的解决方案吗?有没有其他解决方案?添加命名空间需要更改一堆文件,我不知道以后是否会产生不必要的影响。
The obvious solution is to wrap all the original library in a namespace and then calling it by name- that should avoid the ambiguity. But is that the wisest solution? Is there any other solution? Adding a namespace would require changing a bunch of files and I don't know if it would have unwanted repercussions later.
可以做Dib建议,稍加修改:
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
这允许你#define排除,重新获得冲突,否则使用所有符号作为全局符号。
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.