template并不是一个函数,而是用来声明模板的关键字,为了泛型编程。
另外你min方法是作用在vector上的,不能对intArray求min。程序应该这么写
//声明如下,最好别取min这个名字,c++里已经有min的宏定义
template
elemType mymin( elemType *first, elemType *last);
//
int main()
{
int intArray[] = {5, 10, 7, 9, 1, 4, 2},
N = sizeof(intArray)/sizeof(int);
int minInt = mymin(intArray, intArray+N); //调用时参数是首尾指针
cout << minInt;
}
//函数实现
template
elemType mymin( elemType *first, elemType *last)
{
int minElem = *first;
while(++first != last)
{
if(minElem > *first)
minElem = *first;
}
return minElem;
}