Use of typename keyword with template function parameters

后端 未结 3 2058
故里飘歌
故里飘歌 2020-12-02 16:07

In C++, the typename keyword is needed so the compiler can disambiguate between nested types and nested values in templates. However, there are certain situati

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 16:10

    Would be interesting to find what is causing this.

    I've been trying to read the standard in search for an answer, please note I'm am novice in this.

    However I believe I've found a relevant clause.

    §14.6.2. A name used in a template declaration or definition and that is dependent on a template-parameter is assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified by the keyword typename.

    I guess this implies that the issue is in the difference of how name lookup works for base specifier lists and function arguments.

    Base specifier name lookup:

    §10.2. During the lookup for a base class name, non-type names are ignored (3.3.10).

    Which explains why typename is not required for base specifiers.

    Still looking for function argument name lookup.

    Please correct me if this is an incorrect or irrelevant assumption. In the meantime I while keep digging.

    The error given by VS2010 when not qualifying the template argument in the function declaration is the following:

    'T::type' : dependent name is not a type prefix with 'typename' to indicate a type.

    However, I'm still unclear about the rules for dependent function argument name lookup...

提交回复
热议问题