When should I use the keyword “typename” when using templates

后端 未结 4 1953
無奈伤痛
無奈伤痛 2020-12-11 23:10

I\'ve been working lately on a small project, and I couldn\'t figure out something..

I\'ve been given a .h file that was containing a class, using a typename templat

4条回答
  •  忘掉有多难
    2020-12-11 23:17

    typename and class are equivalent in template type parameter list:

    template  class C;
    

    is the same as

    template  class C;
    

    Where the typename is required is when referring to dependent names:

    template  struct A {
        typedef typename T::some_type container;
    };
    

提交回复
热议问题