最近在写c++pp的一道练习题时发现了一些有趣的问题,在此分享一下。
题目考察的主要是函数模板及其显式具体化相关知识,在此为节省空间就不放出来了,以下是我最开始写成的样子
#include <iostream>
#include <cstring>
using namespace std;
template<typename T> T maxn (T [], int);
template<> char * maxn (char * [], int);
int main()
{
int a[6]{0,1,2,3,4,-5,};
double b[4]{4.242,2.0454,45,3.46};
char * c[5]{"asddad415","fa5f4d5sd","vdvd2vd2v2dvd2vd2x","svs","46dsv4dsvsv"};
cout << " The biggest value in array a: " << maxn(a,6) << endl;
ios_base::fmtflags initial;
initial = cout.setf(ios_base::showpoint);
cout << " The biggest value in array b: " << maxn(b,4) << endl;
cout.setf(initial);
cout << " The biggest value in array c: " << maxn(c,5) << endl;
return 0;
}
template<typename T> T maxn (T a[], int lenth)
{
T ret &#