I'm refactoring some code in C++, and I want to deprecate some old methods. My current method for finding all of the methods looks like this:
This totally sucks. I've also tried grepping source for the name of the function calls, but I sometimes run into problems with functions of the same name with different arguments, so my compilation makes the C++ compiler resolve the names for me. I've found this question for C#, but my code base is entirely implemented in C++.
Is there a better way to find all of the callers of a class method or function in C++? I'm using GCC on Unix systems, but cross-platform solutions would be superlative.
GCC allows you to decorate variables, functions, and methods with __attribute__((deprecated))
, which will cause a warning on all callsites (unless -Wno-deprecated-declarations
is given).
class A {
public:
A() __attribute__((deprecated)) {}
};
int main() {
A a;
}
$ g++ test.c test.cc: In function ‘int main()’: test.cc:6: warning: ‘A::A()’ is deprecated (declared at test.cc:3)
Eclipse can do this without any plugins. It can be a useful tool for stuff like this even if you don't want to use it for your day-to-day editor.
You can also use Eclipse's built-in refactoring support to rename overloaded functions so that they're no longer overloaded. Eclipse is also fully cross-platform; you can use features like its indexer, search references, and refactoring even for projects that are maintained and built in other IDEs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With