template function in class in C++
Example
//Sorter.h
#pragma once
class Sorter
{
public:
Sorter(void);
~Sorter(void);
template <class type> static void qsort(type arr[],int start,int end);
};
template <class type> static void Sorter::qsort(type arr[],int start,int end){
int mid=(start+end)/2;
type mid_value=arr[mid];
int i=start,j=end;
do{
while(arr[i]<mid_value&&i<end){
i++;
}
while(arr[j]>mid_value&&j>start){
j--;
}
if(i<=j){
type tmp=arr[i];
arr[i]=arr[j];
arr[j]=tmp;
i++;j--;
}
}while(i<j);
if(i<end){
qsort(arr,i,end);
}
if(j>start){
qsort(arr,start,j);
}
}
The definition should not be in Sorter.cpp file.
RELATED
0 COMMENT
No comment for this article.