类中使用模板

来源:互联网 发布:网络捕鱼7298.com 编辑:程序博客网 时间:2024/05/19 23:27

#include   <iostream.h>  
  #include   <string>  
  using   namespace   std;  
  struct   Student  
  {  
  int   age;  
  };  
   
   
  template<typename   T>  
  class   MyStudent  
  {  
   
  public:  
  Student   A[10];  
  MyStudent(void);  
  InsertionSort(T   A[],int   n);  
  int   GetElem(void);  
  };  
   
  template<typename   T>   MyStudent<T>::MyStudent()  
  {}  
  template<typename   T>   MyStudent<T>::InsertionSort(T   A[],int   n)  
  {  
  int   i,j;  
  T   temp;  
  for(i=1;i<n;i++)  
  {  
  j=i;  
  temp.age=A[i].age;  
  while(j>0&&temp.age<A[j-1].age)  
  {  
  A[j].age=A[j-1].age;  
  j--;  
  }  
  A[j].age=temp.age;  
  }  
  }  
  template<typename   T>   int   MyStudent<T>::GetElem(void)  
  {  
  }  
  main()  
  {  
   
  }