简体   繁体   English

如何使用 Eclipse CDT 自动将 class 带出命名空间?

[英]How can I take a class out of a namespace automatically with Eclipse CDT?

I have a class A that is inside a namespace N in C++, so I can refer to it in the code with N::A.我有一个 class A,它位于 C++ 的命名空间 N 内,因此我可以在代码中使用 N::A 引用它。

I need, in Eclipse CDT, to take that class out of the namespace N .我需要在 Eclipse CDT 中将 class 带出命名空间N
Of course, I also need to edit all the occurrencies that refer to such class with the N::A notation in the codebase, so that the part referring to the namespace N is removed.当然,我还需要在代码库中使用N::A表示法编辑所有引用此类 class 的出现,以便删除引用命名空间N的部分。

I was wondering if, in Eclipse, there is a way to do that automatically, so that I don't have to do it manually everywhere in the code.我想知道在 Eclipse 中是否有一种方法可以自动执行此操作,这样我就不必在代码中的任何地方手动执行此操作。

One plausible method is by using using N::A to load the class A to the global namespace.一种可行的方法是using N::A将 class A加载到全局命名空间。 And then you can use the Eclipse CDT's find and replace feature to edit out all the N::A occurrences to A .然后您可以使用 Eclipse CDT 的查找和替换功能将所有出现的N::A编辑为A

You can either place using N::A only in the files where you want the class to be in the global namespace or else you can define it at the end of the class's header file so that it will automatically be defined in every file which includes the class.您可以仅将using N::A放置在您希望 class 位于全局命名空间中的文件中,或者您可以在类的 header 文件的末尾定义它,这样它将在每个文件中自动定义,其中包括class。 Using it this way means that only the A class gets dumped to the global namespace whereas using using namespace N;以这种方式使用它意味着只有A class 被转储到全局命名空间,而使用using namespace N; dumps every single content of that namespace to the global namespace.将该命名空间的每一个内容转储到全局命名空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM