Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all references of a particular class's overloaded operator in Visual Studio?

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.

like image 763
Andrew Avatar asked Aug 02 '11 19:08

Andrew


3 Answers

Temporarily make the operator private and unimplemented. That will catch the uses when you compile.

like image 119
Mark B Avatar answered Nov 15 '22 23:11

Mark B


Comment out the operator== declaration in the class and recompile. All the places that try to use the function will generate an error.

like image 45
Mark Ransom Avatar answered Nov 15 '22 22:11

Mark Ransom


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
like image 33
Benoit Avatar answered Nov 15 '22 22:11

Benoit