views:

121

answers:

3

Is there any way to quickly visually identify overloaded operators in c++ using Visual Studio?

One of the big gotchas IMO in c++ is not knowing that the operator you are using is overloaded.

Is there something within Visual Studio or some third party tool which will automatically highlight or color-code overloaded operators?

+1  A: 

I don't know if there is a tool for this special use case, but for all sorts of anhanced syntax highlithing, refactoring and so on there is Visual Assist X, an add-in for Visual Studio.

Holger Kretzschmar
Well, I don't see how this answers the question, but I guess I have to give +1 for suggesting VAX anyway.
sbi
+1  A: 

AFAIK, Visual Assist really does a lot of enchanced syntax highlighting, but does not highlight overloaded operators. Correct me if I'm wrong.

If you need to do much code exploring, I suggest doing it in Eclipse+CDT. Among many other useful features it also highlights overloaded operators.

Paul
Correct, VA does not highlight overloaded operators.
sean e
A: 

OP here. Thanks for the responses so far.

My question was based on the idea of working with non-built-in types. The gotcha that triggered this question came from our in-house smart pointer class. If a function returns a smart pointer, the reference count is increased and the caller is responsible for releasing it.

So if you use an = sign instead of our .Attach() call when calling something which returns a smart pointer (and assuming you want to take ownership of the pointer that's returned), you'll get a memory leak. (The = sign is supposed to be used to reference an object and use it for later.)

The equals sign is normally an innocent-looking thing, so I was looking for a way to highlight them when using this class to indicate that they're not "normal".

Another thought -- is there any way to highlight an operator and do a F12 (or something similar) to quickly jump to the overloaded operator code?

overloadedoperator
This really belongs as an edit to the question, SO is not a forum. - However, it sounds that the semantics of this "smart" pointer are just broken. This is not a "gotcha" of operator overloading as such which is based on the premise that the operator "makes sense". If you can't decide what copying and assigning should mean for a class, perhaps disable them altogether, and use named functions for both creating strong and weak pointers.
UncleBens
I second UncleBens' statement. Also look here: http://stackoverflow.com/questions/1437053/1437748#1437748
sbi