On 22-1-2014 22:17, Martin Owens wrote:
On Wed, 2014-01-22 at 21:53 +0100, Johan Engelen wrote:
> There is no name clash (the one is "DrawingContext::Save::_ct", the
> other "DrawingContext::_ct"), but it is confusing and I agree the
> former should be changed.
Since C++ is a type-safe language, is there any lint module that can
find these errors? variable names with different types?
Not sure exactly what you mean.
(To be clear, the code is not an error for the compiler.)
Some more explanation perhaps helps:
Note that the Save class is not part of the DrawingContext class. It is
merely defined in the namespace DrawingContext. There are two separate
classes defined there: "DrawingContex::Save" and "DrawingContext".
(ironically, DrawingContext is actually a part of the
DrawingContext::Save class, as a member variable. So in the Save class,
you could write "_ct->_ct", were it not that _ct is a private member of
DrawingContext)
Scanning for duplicate variable names with different types in a file (or
translation unit) is pointless, because it is bound to happen a lot for
short variable names.
Using grep, as David described, to find the declaration or definition of
a variable name without looking at the context around the grep results
is rarely a viable strategy I would think (especially if you search
through an entire folder). You have to trace the scope hierarchy
manually (e.g. function body -> class declaration -> base class
declaration(s)), or use an editor that understands that.
Ciao,
Johan