What is the difference between writing a template in c++ in the below both ways
template<typename T>
& template<class T>
and when do we prefer them above each other?
If both are same,then why do we have them both if one is enough?
c++templates
What is the difference between writing a template in c++ in the below both ways
template<typename T>
& template<class T>
and when do we prefer them above each other?
If both are same,then why do we have them both if one is enough?
Best Answer
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
andclass
are equivalent. ยง14.1.2 says:Stan Lippman explains this in his article:
Why C++ Supports both Class and Typename for Type Parameters?