1

What's the difference between template<typename T> and template<class T> ?

I always use the "typename" version, but I came across with this class one and I need to know the difference..

J. Seixas
  • 57
  • 1
  • 1
  • 9
  • [And here's another Q&A with more opinions on `class` vs `typename`](http://stackoverflow.com/questions/213121/use-class-or-typename-for-template-parameters). – Cornstalks Jun 13 '16 at 14:54

1 Answers1

2

There is no difference. You can use either typename or class to designate a type parameter in a template.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • 1
    Well there is but in the OP's example there isn't – NathanOliver Jun 13 '16 at 14:53
  • @Kerrek I thought it may differ because `class` only for classes.. and therefore `typename` for a specific case.. – J. Seixas Jun 13 '16 at 14:54
  • @J.Seixas: You may have thought that, but in spite of that, there is no difference. – Kerrek SB Jun 13 '16 at 14:55
  • @NathanOliver what do you mean? – J. Seixas Jun 13 '16 at 14:56
  • @J.Seixas From the answer in the linked to dupe if you have `template < template < typename, typename > class Container, typename Type >` `class Container` cannot be replaced with `typename Container` – NathanOliver Jun 13 '16 at 14:58
  • @NathanOliver so there is no "big" difference . Appreciated – J. Seixas Jun 13 '16 at 15:07
  • @KerrekSB ideone is broken or not showing warnings. That is a C++17 feature: http://coliru.stacked-crooked.com/a/ea079e6d967d4389 – NathanOliver Jun 13 '16 at 15:36
  • @KerrekSB What standard are you looking at? I don't have the actual C++14 standard but I have draft N3797 Which should be the C++14 standard and it is not in there. Also according to [this](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/) it has yet to be adopted. – NathanOliver Jun 13 '16 at 15:44
  • @NathanOliver: Your first comment doesn't seem to apply. The difference concerns template parameters, but my answer is explicitly constrained to type parameters. – Kerrek SB Jun 13 '16 at 16:41