Topic: OK to have member of type T named T?
Author: alfps@start.no ("Alf P. Steinbach")
Date: Sat, 13 May 2006 14:13:02 GMT Raw View
The following problem popped when trying to compile Microsoft's
[gdiplus.h] with MingW g++ 3.3.4; sanitized version:
struct Boo {};
struct Foo { Boo Boo; };
int main() {}
In the original code Boo is a typedef for int (I think); anyway, g++
3.4.4 says
error: declaration of `Boo Foo::Boo'
error: changes meaning of `Boo' from `struct Boo'
Is the compiler within its rights, according to the standard?
MSVC 7.1 and Comeau online 4.3.3 both accept the code.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Tom s" <NULL@NULL.NULL>
Date: 13 May 2006 15:20:01 GMT Raw View
> error: declaration of `Boo Foo::Boo'
> error: changes meaning of `Boo' from `struct Boo'
I've gotten that as a warning before... but never understood what it
meant. It gave me the warning for code akin to the following:
template<class T>
class Monkey {
public:
typedef T T;
};
I was employing the typedef so that I could you T outside of the class,
e.g.:
Monkey<T>::T object;
-Tom s
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: v.Abazarov@comAcast.net ("Victor Bazarov")
Date: Sat, 13 May 2006 16:22:21 GMT Raw View
"Alf P. Steinbach" wrote:
> The following problem popped when trying to compile Microsoft's
> [gdiplus.h] with MingW g++ 3.3.4; sanitized version:
>
> struct Boo {};
> struct Foo { Boo Boo; };
>
> int main() {}
>
> In the original code Boo is a typedef for int (I think); anyway, g++
> 3.4.4 says
>
> error: declaration of `Boo Foo::Boo'
> error: changes meaning of `Boo' from `struct Boo'
>
> Is the compiler within its rights, according to the standard?
>
> MSVC 7.1 and Comeau online 4.3.3 both accept the code.
AFAIK, if Boo is a typedef for 'int', it's different. You are allowed
to "hide" a class Boo declaration in any scope with a variable simply
because class Boo is still available through the "elaborated type
specifier" (in this case 'struct Boo'). It would not be the case if
'Boo' is a typedef.
V
--
Please remove capital As from my address when replying by mail
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Sat, 13 May 2006 17:17:45 CST Raw View
"Alf P. Steinbach" wrote:
> The following problem popped when trying to compile Microsoft's
> [gdiplus.h] with MingW g++ 3.3.4; sanitized version:
>
> struct Boo {};
> struct Foo { Boo Boo; };
>
> int main() {}
>
> In the original code Boo is a typedef for int (I think); anyway, g++
> 3.4.4 says
>
> error: declaration of `Boo Foo::Boo'
> error: changes meaning of `Boo' from `struct Boo'
>
> Is the compiler within its rights, according to the standard?
In this example, providing the elaborated type specifier fixes the
problem:
struct Boo {};
struct Foo { struct Boo Boo; };
If Boo is a typedef, then a different fix is in order:
typedef int Boo;
struct Foo { ::Boo Boo; };
I suspect that neither change should be strictly necessary, since I
believe that inner Boo should simply hide the outer Boo's name within
Foo's class scope.
Greg
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]