I writed a Vector class of my own, like the standard one.
I've haded it a sort method to sort the elements by a user defined funtion comparation, of using operator<.
When compiling, I get this error:
error C2896: 'void __cdecl quicksort(C *,int,int,int (__cdecl *)(const C &,const C &))' : cannot use function template 'int __cdecl defcmp(const C &,const C &)' as a function argument
d:\...\vector.cpp(223) : see declaration of 'defcmp'
Basicly, I think, that the compiler isn't associating the template in the quicksort function with the one from the defcmp function...
How can I solve this??
Code:
/*.........*/
template<class C>
class Vector{
private:
C* _vector;
int _size;
/*...............*/
};
template<class C>
void quicksort(C* vec,int low, int high,int (*f_cmp)(const C&, const C&)){
/*....................*/
}
template<class C>
void Vector<C>::sort(int (*f_cmp)(const C&, const C&)){
quicksort(_vector,0,_size-1, f_cmp);
}
template<class C>
int defcmp(const C& c1, const C& c2){
return (c1<c2) ? -1 : ( (c2<c1) ? 1 : 0);
}
template<class C>
void Vector<C>::sort(){
quicksort(_vector,0,_size-1, defcmp);
}
I don't want to had the quicksort funtion to my class's scope, nor store the comparation function pointer in it.
Thanks in advance.