Templates in c++,typename and class

后端 未结 2 1238
执念已碎
执念已碎 2020-12-20 20:16

What is the difference between writing a template in c++ in the below both ways

template & template<

相关标签:
2条回答
  • 2020-12-20 20:49

    No difference at all. I prefer first one (mostly), but that is my personal taste. The language doesn't make any difference between them.

    For template parameters, the keywords typename and class are equivalent. §14.1.2 says:

    There is no semantic difference between class and typename in a template-parameter.


    If both are same,then why do we have them both if one is enough?

    Stan Lippman explains this in his article:

    Why C++ Supports both Class and Typename for Type Parameters?

    0 讨论(0)
  • 2020-12-20 20:52

    These keywords are there because of historical reason. There's no difference between them. Read this: http://blogs.msdn.com/b/slippman/archive/2004/08/11/212768.aspx

    0 讨论(0)
提交回复
热议问题