重命名命名空间 [英] Renaming namespaces

查看:168
本文介绍了重命名命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做C ++很长一段时间,但我只是面对一个问题,我不能给一个答案:是否可能创建命名空间在C + +的别名?

I've been doing C++ for a long time now but I just faced a question this morning to which I couldn't give an answer: "Is it possible to create aliases for namespaces in C++ ?"

让我举个例子。让我们假设我有以下标题:

Let me give an example. Let's say I had the following header:

namespace old
{
  class SomeClass {};
}

其中,由于未指明的原因必须成为:

Which, for unspecified reasons had to become:

namespace _new
{
  namespace nested
  {
    class SomeClass {}; // SomeClass hasn't changed
  }
}

一个旧的代码库,引用 SomeClass ,我可以通过添加以下内容快速(和肮脏)修复更改:

Now if I have an old code base which refers to SomeClass, I can quickly (and dirtily) "fix" the change by adding:

namespace old
{
  typedef _new::nested::SomeClass SomeClass;
}

但是有一种方法可以导入一切 _new :: nested 进入 old ,无需 typedef 每个类型?

But is there a way to import everything from _new::nested into old without having to typedef explicitely every type ?

类似于Python的 import * from ...

Something similar to Python import * from ....

谢谢。

推荐答案

using namespace new::nested;

Ideone示例< a>。

Example at Ideone.

或者如果您确实想要一个真实的别名:

Or if you actually want a real alias:

namespace on = one::nested;

Ideone示例< a>。

Example at Ideone.

这篇关于重命名命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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