Class Name Before Scope Operator ?

template<class T>
Pair<T>::Pair(T firstValue, T secondValue)
{
. . .


Why the <T> is here ?What it's for ?

Would love to have a simple and understandable code as an explanation.

Thanks !

P/S : I have to ask because I saw it the first time and I haven't use it before.
Hi ,
T is for genricacity , T represent any type of data type .
so firstvalue and the second value could be any type of data type .
If <T> was ommitted,what would happen ?
Templates! <3

That <T> is an indication that your T being used by the class member template is the same T being used by the rest of the class (the class is a template). If you were to omit it, I expect that that function would be a little bit more... flexible in terms of what types it accepts. To be honest, I've never tried omitting the additional set of brackets.

For more information: http://cplusplus.com/doc/tutorial/templates/

Happy programming.

-Albatross

Last edited on
Ahhh,it means that if <T> was replaced by int then only int is accepted in place of T in class definition or wherevever T is ?

That was helpful.Thanks ! <3
Topic archived. No new replies allowed.