开发者

Renaming namespaces

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) "f开发者_如何学Pythonix" 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.


using namespace new::nested;

Example at Ideone.

Or if you actually want a real alias:

namespace on = one::nested;

Example at Ideone.


This:

namespace old = newns::nested;

would seem to be what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜