不能將函數 模板“void selectionSort(T [],int)”用作函數參數
不能將函數 模板“void selectionSort(T [],int)”用作函數參數
分別定義如下:? 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)”:?未能從“重載函數類型”為“重載函數類型”推導?模板?參數 ????????調用修改為SortHelper::SortTime("Selection?Sort",?selectionSort<int>,arr,n);后,再次報錯 ????????MSVCRTD.lib(crtexew.obj)?:?error?LNK2019:?unresolved?external?symbol?_WinMain@16?referenced?in?function?___tmainCRTStartup1>F:\C++程序\Selection_Sort(2)\Debug\Selection_Sort(2).exe?:?fatal?error?LNK1120:?1?unresolved?externals ????????請問是為什么呢?
2019-03-30
已解決,我把控制臺應用程序建成控制臺程序了,不好意思多有打擾