template <class T>
bool cmp(const T &a, const T &b){
return a <= b;
}
template <class T>
void bubble_sort(T tablica[], int size, bool compare(T,T)){
bool change = true;
while(change){
change = false;
for(int i=0; i < size-1; ++i){
if(compare(tablica[i+1], tablica[i])){
zamien(tablica[i+1], tablica[i]);
change = true;
}
}
}
}
It doesn't work, I have errors:
'void bubble_sort(T [],int,bool (__cdecl *)(T,T))' :
could not deduce template argument for 'T []' from 'int [10]'
'void bubble_sort(T [],int,bool (__cdecl *)(T,T))' :
cannot use function template 'bool cmp(const T,const T)' as a function argument'
but when I replace a cmp function with that:
bool cmp(const int a, const int b){
return a <= b;
}
Everything works fine. How to change my cmp function to work with templates?
compare(T,T)tocompare (const T &, const T &)and commented out thezamienline. Changingzamientostd::swapproduced correct results when the numbers were different at least.