V
vilhelm.sjoberg
Hello,
I am a resonably confident C programmer, but not very sure about the
dark corners of C++. Recently, I had G++ give me a strange error.
The program in question is in essence:
struct foo {
};
struct bar {
foo foo;
};
That is, I try to declare a member variable called "foo". However, G++
complains that:
Foo.C:5: error: declaration of `foo bar::foo'
Foo.C:1: error: changes meaning of `foo' from `struct foo'
Changing the line to
struct foo foo;
makes the compiler happy. However, Microsoft Visual C++ does not give
any error at all for the code.
So, which compiler is right here? If G++ is correct, what rule of C++
am I violating, and what is the reason this restriction was introduced?
Thanks in advance for any replies.
I am a resonably confident C programmer, but not very sure about the
dark corners of C++. Recently, I had G++ give me a strange error.
The program in question is in essence:
struct foo {
};
struct bar {
foo foo;
};
That is, I try to declare a member variable called "foo". However, G++
complains that:
Foo.C:5: error: declaration of `foo bar::foo'
Foo.C:1: error: changes meaning of `foo' from `struct foo'
Changing the line to
struct foo foo;
makes the compiler happy. However, Microsoft Visual C++ does not give
any error at all for the code.
So, which compiler is right here? If G++ is correct, what rule of C++
am I violating, and what is the reason this restriction was introduced?
Thanks in advance for any replies.