We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Templates are used for generic, type independent programming. Templates are used to declare variable of any valid C++ type. It means that you can declare fuctions of class without initially specifying the type. Like this...
But while using function with templates you can simply call them. Like...
stringa,b,c;c=fn(a,b);
However while declaring objects you need to specify the type. Like...
abc<int>a;intb,c,d;d=a.func(b,c);
Can you see this looks familiar. Yeah.. "vectors" and "maps" and so on.... they are defined using templates (that is why we call it STL standard template library).
However this problem is about template specialization. We use template specialization when we need the function to behave differently for a specific type. You can read about templates and templates specialization here...
C++ Class Template Specialization
You are viewing a single comment's thread. Return to all comments →
Templates are used for generic, type independent programming. Templates are used to declare variable of any valid C++ type. It means that you can declare fuctions of class without initially specifying the type. Like this...
See how you can you declare new variables with the template T. Similarly you can define new classes or structures with templates.
But while using function with templates you can simply call them. Like...
However while declaring objects you need to specify the type. Like...
Can you see this looks familiar. Yeah.. "vectors" and "maps" and so on.... they are defined using templates (that is why we call it STL standard template library).
However this problem is about template specialization. We use template specialization when we need the function to behave differently for a specific type. You can read about templates and templates specialization here...
http://www.tutorialspoint.com/cplusplus/cpp_templates.htm
and here also....
http://www.cplusplus.com/doc/tutorial/templates/
And typename is not a thing to worry about you can write class insted of typename if it feels better.
I hope it helped.
thank you sir...it really helped!
My pleasure...