移植旧代码时如何处理类名冲突? [英] How to handle a class name conflict when porting old code?

查看:116
本文介绍了移植旧代码时如何处理类名冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一个旧的库(尽管我可以告诉使用命名空间)移植到现代编译器。我的一个目标不能告诉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.

这篇关于移植旧代码时如何处理类名冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆