我从事 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;
或者如果你真的想要一个真正的别名:
namespace on = one::nested;
关于c++ - 重命名命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6108704/