Merge pull request #264 from Not-envious-of-immortals/master
修改模板特化代码bug
This commit is contained in:
commit
20eb89e15d
@ -8,14 +8,19 @@ T Max(T a,T b) {
|
|||||||
}
|
}
|
||||||
//特化
|
//特化
|
||||||
//template <> 返回类型 函数名<特化的数据类型>(参数表) {}
|
//template <> 返回类型 函数名<特化的数据类型>(参数表) {}
|
||||||
|
template<>const char * Max<const char *>(const char *a,const char *b) {
|
||||||
|
return (strcmp(a,b)>=0)?a:b;
|
||||||
|
}
|
||||||
template<>char * Max<char *>(char *a,char *b) {
|
template<>char * Max<char *>(char *a,char *b) {
|
||||||
return (strcmp(a,b)>=0)?a:b;
|
return (strcmp(a,b)>=0)?a:b;
|
||||||
}
|
}
|
||||||
int main(){
|
int main(){
|
||||||
float c=5.1,d=3.2;
|
float c=5.1,d=3.2;
|
||||||
cout<<"2,3的最大值是:"<<Max(3,2)<<endl;
|
char s1[]="xyce", s2[]="xbv";
|
||||||
cout<<"c,d的最大值是:"<<Max(c,d)<<endl;
|
cout<<"2,3的最大值是:"<<Max(3,2)<<endl;
|
||||||
cout<<Max("xbv","xyce")<<endl;
|
cout<<"c,d的最大值是:"<<Max(c,d)<<endl;
|
||||||
|
cout<<Max("xbv","xyce")<<endl;
|
||||||
|
cout<<Max(s1,s2)<<endl;
|
||||||
system("pause");
|
system("pause");
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user