简体   繁体   中英

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.

I need, in Eclipse CDT, to take that class out of the namespace 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.

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.

One plausible method is by using using N::A to load the class A to the global namespace. And then you can use the Eclipse CDT's find and replace feature to edit out all the N::A occurrences to 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 it this way means that only the A class gets dumped to the global namespace whereas using using namespace N; dumps every single content of that namespace to the global namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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