When the member functions of a template class defined outside of the class, each function preceded by the function template.

            It takes the following general format:

template<class  T>
 return_type    class_name <T> :: memberfunction_name(arguments)
{
             - - - - - - - -
             Body of member function
             - - - - - - - -
                               }

/*Program to illustrate member function template */

#include<iostream.h>
template <class T>
class Sample
{
           T   x;
           public:
                     Sample(T  a)
                          {  
                                  x = a;
                           }
                      void  show( );
}; 
template <class T>
void Sample <T> : : show( )       //member function template
{
         cout <<Input:<< x <<endl;
}
int  main( )
{
          Sample <int> S1(10);
          Sample <float> S2(8.45);
          S1.show( );
          S2.show( );
          return  0;
}

Output:           Input: 10
                        Input: 8.45
Posted by Unknown On 00:11 No comments

0 comments:

Post a Comment

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

Blog Archive

Contact Us


Name

E-mail *

Message *