c++ - 重命名命名空间

标签 c++ namespaces alias

我从事 C++ 已经有很长时间了,但今天早上我遇到了一个无法回答的问题:“是否可以在 C++ 中为命名空间创建别名?”

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

namespace old
{
  class SomeClass {};
}

由于不明原因必须变成:

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

现在,如果我有一个引用 SomeClass 的旧代码库,我可以通过添加:

快速(且肮脏地)“修复”更改:
namespace old
{
  typedef _new::nested::SomeClass SomeClass;
}

但是有没有办法将 everything_new::nested 导入 old 而无需 typedef明确每种类型?

类似于 Python import * from ....

谢谢。

最佳答案

using namespace new::nested;

Example at Ideone .

或者如果你真的想要一个真正的别名:

namespace on = one::nested;

Example at Ideone .

关于c++ - 重命名命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6108704/

相关文章:

c++ - 如何安装系统范围的 nuget 包?

c++ - 从自定义值中修剪 vector 的最佳方法

php - 如何使用 php 扩展访问类中的变量?

python - 尽管 ~/.bashrc 和 ~/.bash_aliases 中有导出和别名,但终端中的默认 python 不会改变

mysql - 每个派生表都必须有自己的别名,但是给所有子查询的别名都会出错

c++ - 变量的 const 和 volatile 顺序

C++ 将类添加到命名空间 : why?

r - BiodiversityR 包加载失败

php - php 未使用的导入会影响性能吗?

c++ - clang 或 gcc 是否利用引用限制进行别名分析