class template

Class template :

A single class specification that would work for variables of all types, instead of a single basic type can be done using class template. 

below is the example to demdemonstrate

Template <class t>

Class c

{

private: t a,b;

public: t  show (t x)

{

cout <<x;

}

}

int main()

{

c<int> s;

s.show(10);

s.show(2.456);

return 0;

}

Advantages 

Reduce the burden of programmer to write the same code for the different types by generalising the class 

Posted on by