Base::Foo
and Derived::Foo
are indeed the same type, a class is just a compound type(from the draft C++ standard section 3.9.2
) and we would not expect a type inherited from a base class to be a different type in the derived class. For example if Base
contained:
typedef int newType1 ;
as long as Derived
did not redeclare newType1
then we would expect Base::newType1
and Derived::newType1
to be the same type and a nested class is no different. If we refer to the draft standard section 9.2
Class members paragraph 1 says(emphasis mine):
[...]Members of a class are data members, member functions (9.3), nested types, and
enumerators. Data members and member functions are static or non-static; see 9.4. Nested types are
classes (9.1, 9.7) and enumerations (7.2) defined in the class, and arbitrary types declared as members by use of a typedef declaration (7.1.3).
That confirms that intuition nested classes are just types(and also members), for completeness sake section 9.7
referenced above is the nested class section and from section 10
Derived classes paragraph 1 we see:
[...]Unless redeclared in the derived class, members of a base class are also considered to be members of the derived class.[...]
Since they are the same type the catch will work fine.