1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 分别定义如下: template < typename T> void SortTime( string sortName, void (*sort)(T[], int ), T arr[], int n) { clock_t startTime = clock (); sort(arr ,n); clock_t endTime = clock (); assert ( isSorted(arr , n)); cout<<sortName << " :" << double (endTime-startTime) /CLOCKS_PER_SEC << " s" <<endl; return ; } ----------------------------------------------------------------------------------------------------- template < typename T> void selectionSort(T arr[], int n){ for ( int i = 0 ; i < n ; i ++){ int minIndex = i; for ( int j = i + 1 ; j < n ; j ++ ) if ( arr[j] < arr[minIndex] ) minIndex = j; swap( arr[i] , arr[minIndex] ); } } 调用如下: SortHelper::SortTime( "Selection Sort" , selectionSort,arr,n); |
报错:
1>c:\algorithm\selectionsort\selectionsort\main.cpp(28): error C2896: “void SortHelper::SortTime(std::string,void (__cdecl *)(T [],int),T [],int)”: 不能将函数 模板“void selectionSort(T [],int)”用作函数参数
1> c:\algorithm\selectionsort\selectionsort\main.cpp(8) : 参见“selectionSort”的声明
1>c:\algorithm\selectionsort\selectionsort\main.cpp(28): error C2784: “void SortHelper::SortTime(std::string,void (__cdecl *)(T [],int),T [],int)”: 未能从“重载函数类型”为“重载函数类型”推导 模板 参数
请问这个该如何解决 多谢 !