开发者

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 Studi开发者_如何学JAVAo, 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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜