Possible Duplicate:
Why are redundant scope qualifications supported by the compiler, and is it legal?
Can i actually write code like
class Foo
{
public:
Foo();
};
Foo::Foo::Foo::Foo::Foo::Foo() {}
gcc compiles it. What’s the reason for adding this feature?
The feature is that the name of the type is injected inside the class scope, that is, there is an implicit
typedef Foo Foo;of sorts inside the classFoo.The feature is in the language because in several constructs the nested type is required. For example, when disabling dynamic dispatch by explicitly naming the level of the hierarchy where the overrider is to be selected (
obj.Base::f()).The original list had some 10 odd constructs for which the name had to be present, and it was simplified by making the nested name available in all contexts, which in turn means that it allows for the funny syntax you wrote.