If I have a class that contains an overloaded == operator function, how do I find out where this overloaded operator is being used throughout the code? (Other than placing a break point inside the overloaded == method and seeing if the code ever hits it.) I tried going to the class view in Visual Studio, right clicking on the method, and selecting "Find all references" but it claims there are no references when I know there is at least one that I added.
Temporarily make the operator private and unimplemented. That will catch the uses when you compile.
Comment out the operator==
declaration in the class and recompile. All the places that try to use the function will generate an error.
An update on Mark B's answer: mark the function declaration with =delete
. This will work with all modern versions of Visual Studio, and also works with free functions.
class Foo {
bool operator == (const Foo &rhs) const =delete;
}
bool operator == (const Bar &lhs, const Bar &rhs) = delete;
...
Foo f1, f2;
if(f1 == f2) { // C2280 (…) : attempting to reference a deleted function
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