我有一个中值函数,它从数组元素中找到中值,如下所示
中位数.h
template <class N>
N median (N*,size_t);
中位数.cpp
#include "median.h"
template <class N>
N median (N* numbers,size_t size){
size_t mid = size/2;
return size % 2 == 0? (numbers[mid] + numbers[mid-1])/2 : numbers[mid];
}
主要的
#include <iostream>
#include "median.h"
using namespace std;
int main(){
double Numbers [] = {1,2,3,4,5,6,7};
size_t size = sizeof(Numbers)/sizeof(*Numbers);
double med = median(Numbers,size);
cout << med << endl;
return 0;
}
但我收到以下错误
main.obj : error LNK2019: unresolved external symbol "double __cdecl median<double>(double *,unsigned int)" (??$median@N@@YANPANI@Z) referenced in function _main