function template
e.g.
#include<iostream>
using namespace std;

void Print(int A[], const int n)
{
  for (int i=0; i<n; i++)
      cout << A[i] << " ";
  cout << endl;
}

int main()
{
  int a[5] = {1,2,3,4,5};
  float b[3] = {1.2,3.4,5.6};

  Print(a,5);
  Print(b,3);   //illegal ....

  system("pause");
  return 0;

}

Solution?
1. Create Print_int, Print_float,.... for each type.
2. use function template.

e.g.
#include<iostream>
#include<string>
using namespace std;
template<class T>   
// It is not end by ';', T can be changed to any name
void Print(T A[], const int n)
{
  for (int i=0; i<n; i++)
      cout << A[i] << " ";
  cout << endl;
}

int main()
{
  int a[5] = {1,2,3,4,5};
  double b[3] = {1.2,3.4,5.6};
  char c[6] = "Hello";
     string d[4] = {"one", "two", "three", "four"};

  Print(a,5);
  Print(b,3);   //OK
  Print(c,6);   //OK
  Print(d,4);   //OK
  system("pause");
  return 0;

}

 

class template

     Similar to function template.  No specific type given for array element type.  
                                                 The actual type is given during the declaration of objects.
Declaration 1.
 
  class CL
  {
     ....
     ....
     int A[10];
  };

 

 

 

Declaration 2.
 
     template<class T>     
//It is not end by ";".  T can be changed to any name
   class CL
  {
     ....
     ....
     T A[10];
  };
 

CL<int> OBJ1;  // A in OBJ1 is an array of 10 int.
CL<char> OBJ2; // A in OBJ2 is an array of 10 char.

 Example:

#include<iostream>
#include<string>
using namespace std;
template<class T>
class Sample
{
      private:
              T num[5];
      public:
             Sample (T aNum[5]); //constructor
             T getSum();
            
};
template<class T>
Sample<T>::Sample (T aNum[5])
{
  for(int i=0; i<5; i++)
          num[i]= aNum[i];             
}
template<class T>
T Sample<T>::getSum()
{
    T total = 0;
    for(int i=0; i<5; i++)
    total = total + num[i];
    return total;
}

int main()
{
    int x[5]={8, 6, 4, 7, 10};
    double y[5]={8.8, 6.6, 4.4, 7.7, 10.1};
    Sample<int> Obj(x);                    //When you want to use a template class, you specify a data type.
    Sample<double> Obj2(y);
    cout<<"The sum of first object is "<<Obj.getSum()<<endl;
    cout<<"Sum for 2nd object  is "<<Obj2.getSum()<<endl;
    
    system("pause");
    return 0;
}