Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

c++ - 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.

question from:https://stackoverflow.com/questions/66066993/how-can-i-take-a-class-out-of-a-namespace-automatically-with-eclipse-cdt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...