Templates in C ++, typename and class

What is the difference between writing a template in C ++ in both cases

template<typename T> and template<class T>

and when do we prefer them over each other? If they are both the same, then why do we have both of them, if there are enough of them?

+6
source share
2 answers

No difference. I prefer at first (mostly), but this is my personal taste. Language has no meaning between them.

For template parameters, the keywords typename and class equivalent. ยง14.1.2 states:

There is no semantic difference between the class and typename in the template parameters.


If both are the same, then why do we have both of them, if there are enough of them?

Stan Lippman explains this in his article:

Why does C ++ support both Class and Typename for type parameters?

+9
source

These keywords exist for historical reasons. There is no difference between them. Read this: http://blogs.msdn.com/b/slippman/archive/2004/08/11/212768.aspx

+3
source

Source: https://habr.com/ru/post/886611/


All Articles