We can also use more than one generic data type in a class template, they are declared as a comma-separated list.


The general format is:

template <class T1, class T2, .. . . . . .>
class  class_name
{
          …… … // Body of the class
         
};

/*Program Illustration of class template with multiple parameters*/
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<<”\t<<b<<endl;
}
}; 
int  main( )
{
    Test <int , float>  test1(1, 2.5);      //one is int and second one is float types
    Test <float , char>  test2(10.5, `A); //here one is float and second one is char types
    test2.show( );
} 

Output:           1         2.5
                        10.5         A
Posted by Unknown On 23:26 No comments

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *