-
class templates...
have i finally got the hang of templates ,,,
so making a template class saves you from typing out more class's
just so it can be a diferent type...
Code:
#include <iostream>
using namespace std;
template <class T>
class Temp
{
public:
T Varible; //Varible could be any data type..
private:
protected:
};
int main()
{
Temp<int> TemP;
Temp<double> TemPP; //now the Temp data member Varible can be a double
TemP.Varible = 40;
cout<< TemP.Varible <<endl;
cout<< "int " << sizeof(TemP.Varible) << " " << &TemP.Varible <<endl;
cout<< "double " << sizeof(TemPP.Varible) << " " << &TemPP.Varible <<endl;
//sizeof(TemP.Varible) <<endl;
return 0;
}
-
>> so making a template class saves you from typing out more class's
It may save you typing, but that is never reason to use a template. Although along the same lines, if you use the same code with different types then using a template instead means that future changes need to be made in only one place and there is no chance of not updating all the necessary copies.