Nested classes are dependent types in class templates?
考虑下面的:P></
1 2 3 4 5 6 7 8 9 10 11 | template<class> struct T { struct T1 { struct T2 { }; }; /*typename*/ T1::T2 m; }; |
没有
§17.6.2.1?5P></
A name is a member of the current instantiation if it is
— An unqualified name that, when looked up, refers to at least one member of a class that is the current instantiation or a non-dependent base class thereof.
...
A name is a dependent member of the current instantiation if it is a member of the current instantiation that, when looked up, refers to at least one member of a class that is the current instantiation.
T1是依赖人of the current实例化。T2 is not of the current成员实例化(EN是T1,学院成员)P></
§17.6.2.1?9.3P></
A type is dependent if it is
...
— a nested class or enumeration that is a dependent member of the current instantiation,
...
T1是在套式舱和thus依赖型。P></
§17.6?3P></
When a qualified-id is intended to refer to a type that is not a member of the current instantiation (17.6.2.1) and its nested-name-specifier refers to a dependent type, it shall be prefixed by the keyword typename, forming a typename-specifier. ...
thus,
我的理解是正确的吗?如果我知道这背后的理由,什么茶?我永远
是的,你是对的。
在您的例子中,这并不重要,因为您不可能在不实例化EDOCX1(因为它是类成员)的情况下专门化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | template<class> struct T { struct T1 { struct T2 { }; }; void foo() { typename T1::T2 m; } }; template<> struct T<void>::T1 { int T2; }; |
如果