开发者

Visual Studio C++: Refactoring between member and non-member functions

I have a library, and I need to refactor a class X such that every call of the form:

f(x); //Non-member function

is subsituted with:

x.f(); //Member function

where f is a fixed method (same name in all the code) but x is an instance of type X, and as such will change.

Is there an wasy way to do a globl find and replace which would take care of such 开发者_JAVA技巧conversions?

Just in case, also knowing how to go from the member to the non-member case would be interesting :)

Thank you!


Use the compiler, luke.

Since I cannot image how this could be done via textual replacement, and I very much doubt you have a refactoring tool available that does it[*] for you:

Simply change your class definition accordingly, so that the previous function is no longer available. Then let your compiler tell you where you need to replace the calls to a no-longer-existing function.

[*] : Actually, I doubt there's any refactoring tool for C++ available that is able to achieve this.


Can't imagine so, not without a very advanced refactoring plugin/addon. It's even a little more complicated than you'd expect at first, because you'd also want to change any calls like x->f() into f(*x). Let's not even get into the situation where you have method pointers...


Find and Replace, using regular expressions and tagged groups.

Then you can replace f\({:i}\) with \1.f() and f\(\*{:i}\) with \1->f()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜