Reputation:
My question is simple, why a class and its nested class cannot have same name, but namespaces can?
for example:
class Test {
class Test {};
};
is invalid, but
namespace Test {
namespace Test {}
}
is valid
Upvotes: 3
Views: 306
Reputation: 52601
Class X
already has a member named X
, referring to itself. This is known as an injected class name. It's then invalid to add another member with the same name.
Upvotes: 2