Andrew
Andrew

Reputation: 573

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.

Upvotes: 14

Views: 6707

Answers (4)

Benoit
Benoit

Reputation: 79175

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

Upvotes: 5

Mark B
Mark B

Reputation: 96241

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

Upvotes: 24

Mark Ransom
Mark Ransom

Reputation: 308138

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

Upvotes: 3

user195488
user195488

Reputation:

You can try the add-on Visual Assist. It really does a lot of enchanced syntax highlighting, but I do not think it highlights overloaded operators.

Visual Studio should show you overloaded functions (use the arrows), though AFAIK there is no way to show this for operators.

Upvotes: 0

Related Questions