亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

不能將函數 模板“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
????????請問是為什么呢?


正在回答

1 回答

已解決,我把控制臺應用程序建成控制臺程序了,不好意思多有打擾

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
C++遠征之模板篇
  • 參與學習       91140    人
  • 解答問題       325    個

本C++教程力求即學即會,所有知識以實踐方式講解到操作層面

進入課程

不能將函數 模板“void selectionSort(T [],int)”用作函數參數

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號