重命名命名空间
我已经从事 C++ 工作很长时间了,但今天早上我遇到了一个无法给出答案的问题:“是否可以在 C++ 中为命名空间创建别名?”
让我举个例子。假设我有以下标头:
namespace old
{
class SomeClass {};
}
由于未指定的原因,它必须变成:
namespace _new
{
namespace nested
{
class SomeClass {}; // SomeClass hasn't changed
}
}
现在,如果我有一个引用 SomeClass
的旧代码库,我可以快速(并且肮脏地)“修复”更改添加:
namespace old
{
typedef _new::nested::SomeClass SomeClass;
}
但是有没有一种方法可以将 所有内容从 _new::nested
导入到 old
中,而无需显式 typedef
每种类型?
类似于 Python import * from ...
。
谢谢。
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
}
}
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;
}
But is there a way to import everything from _new::nested
into old
without having to typedef
explicitely every type ?
Something similar to Python import * from ...
.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ideone 中的示例。
或者,如果您确实想要一个真正的别名:
Ideone 的示例。
Example at Ideone.
Or if you actually want a real alias:
Example at Ideone.
这:
似乎就是你想要的。
This:
would seem to be what you want.