Officially, what is typename for?

后端 未结 8 1640
野的像风
野的像风 2020-11-22 15:07

On occasion I\'ve seen some really indecipherable error messages spit out by gcc when using templates... Specifically, I\'ve had problems where seemingly correc

8条回答
  •  执念已碎
    2020-11-22 15:32

    Following is the quote from Josuttis book:

    The keyword typename was introduced to specify that the identifier that follows is a type. Consider the following example:

    template 
    Class MyClass
    {
      typename T::SubType * ptr;
      ...
    };
    

    Here, typename is used to clarify that SubType is a type of class T. Thus, ptr is a pointer to the type T::SubType. Without typename, SubType would be considered a static member. Thus

    T::SubType * ptr
    

    would be a multiplication of value SubType of type T with ptr.

提交回复
热议问题