Difference of keywords 'typename' and 'class' in templates?

后端 未结 5 621
南方客
南方客 2020-11-22 16:37

For templates I have seen both declarations:

template < typename T >
template < class T >

What\'s the difference?

And

5条回答
  •  迷失自我
    2020-11-22 17:22

    While there is no technical difference, I have seen the two used to denote slightly different things.

    For a template that should accept any type as T, including built-ins (such as an array )

    template
    class Foo { ... }
    

    For a template that will only work where T is a real class.

    template
    class Foo { ... }
    

    But keep in mind that this is purely a style thing some people use. Not mandated by the standard or enforced by compilers

提交回复
热议问题