<typename T> vs <class T> | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

<typename T> vs <class T>

I know I just posted another question. Bear with me. Lol So in the c++ templates tutorial, they mention the existence of another definition, where instead of using <class T>, you can use <typename T>. All that is said about typename is that typename and class are similar. What's the difference between the two? Please provide examples if possible.

5th Feb 2019, 5:57 AM
Daniel Cooper
Daniel Cooper - avatar
1 Answer
+ 1
There is no specific difference between class and typename in a template parameter. typename however, is possible in another context when using templates - to hint at the compiler that you are referring to a dependent type. Without typename, the compiler can't tell in general whether you are referring to a type or not.
5th Feb 2019, 7:27 AM
eMBee
eMBee - avatar