Here is the example :
struct A
{
A(const int a ):b(a)
{
}
int b;
};
struct B
{
B() : a(5)
{
}
static void A()
{
}
A a;
};
int main()
{
B::A();
}
And the compiler error is :
a9.cpp:19: error: ‘A’ does not name a type
a9.cpp: In constructor ‘B::B()’:
a9.cpp:24: error: class ‘B’ does not have any field named ‘a’
I am using gcc 4.3.0 on fedora 9.
Can someone explains why is the compiler complaining?
If possible, with references from the standard.
Thanks
This works:
Since you’ve used
Aas a member name inB, that member’s definition shadows theAtype from the outer namespace. Using::you can get to that namespace.This behavior is specified in the (draft) standard as:
3.3.7 (1) “A name can be hidden by an explicit declaration of that same name in a nested declarative region” (the definition of
struct B, which is nested in the namespace wherestruct Ais also defined).Carefully read the introduction to chapter 3, Basic concepts, for further clarification. Especially, this section specifies that
3 (7) Two names are the same if
Note that this last definition does not distinguish between types and class members, so the name hiding (shadowing) rule 3.3.7 (1) applies.