Topic: another scoping question
Author: ssulsky@sybase.com (Stan Sulsky)
Date: 1995/06/30 Raw View
gcc 2.7 refuses to compile the following, because:
t.cpp: In method `int Y::f(enum X::Color)':
t.cpp::10: lookup in the scope of `class X' does not match lookup
in the current scope
The problem is the choice of the variable name `Color' in the
signature of Y::f(X::Color).
Is this correct behavior?
class X {
public:
enum Color { red, green, blue };
int isRed(Color c) { return c == red; }
};
class Y {
public:
X x;
int f (X::Color Color) { return x.isRed(Color); } // line 10
};
--
------
Stan Sulsky | Internet: ssulsky@sybase.com
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/30 Raw View
It looks like a compiler bug to me. I don't see anything wrong with
the code. Of course naming a formal parameter the same as a type
you use in the same function seems unnecessarily confusing to
human readers.
---
Steve Clamage, stephen.clamage@eng.sun.com
In article L1E@sybase.com, ssulsky@sybase.com (Stan Sulsky) writes:
>
>gcc 2.7 refuses to compile the following, because:
>
>t.cpp: In method `int Y::f(enum X::Color)':
>t.cpp::10: lookup in the scope of `class X' does not match lookup
> in the current scope
>
>The problem is the choice of the variable name `Color' in the
>signature of Y::f(X::Color).
>
>Is this correct behavior?
>
>class X {
>public:
> enum Color { red, green, blue };
> int isRed(Color c) { return c == red; }
>};
>
>class Y {
>public:
> X x;
> int f (X::Color Color) { return x.isRed(Color); } // line 10
>};