Saturday, February 2, 2013

Template Class in C++


Template Class:

template <class T1, class T2>
class test
{
 T1 a;
 T2 b;
 public:
 test(T1 x , T2 y)
 {
  a=x;
  b=y;
 }
 void show()
 {
  cout<<a<<”and”<<b;
 }
};

void  main()
{
 test< float , int > test1 (1.30,123);
 test<int , char> test2 (10,’w’);
 test1.show();
 test2.show();
getch();
}

A class created from class template is called a template class.

Syntax:
class_name < type > object_name(argument list);

0 comments:

Post a Comment

Powered by Blogger.