Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "template <class T>" and "template <typename T>"? [duplicate]

Possible Duplicate:
Use 'class' or 'typename' for template parameters?

I see two different template class declarations:

template <class T> class SampleClass1
{
    // ...
};

and

template <typename T> class SampleClass2
{
    // ...
};

What is the difference between these two codes?

EDIT: I corrected the wrong keyword "typedef" to "typename".

like image 441
hkBattousai Avatar asked Dec 26 '10 15:12

hkBattousai


1 Answers

If by

template <typedef T> class SampleClass2

you mean

template <typename T> class SampleClass2

then there is no difference. The use of class and typename (in the context of a template parameter that refers to a type) is interchangeable.

The reason that both keywords are allowed here is historical. See this article for a detailed explanation.

like image 164
Charles Salvia Avatar answered Sep 20 '22 22:09

Charles Salvia