Skip to content

Commit

Permalink
修改模板特化代码bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-envious-of-immortals committed Feb 7, 2023
1 parent 7adc0b5 commit 8cdadc9
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ T Max(T a,T b) {
}
//特化
//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) {
return (strcmp(a,b)>=0)?a:b;
}
int main(){
float c=5.1,d=3.2;
cout<<"2,3的最大值是:"<<Max(3,2)<<endl;
cout<<"c,d的最大值是:"<<Max(c,d)<<endl;
cout<<Max("xbv","xyce")<<endl;
char s1[]="xyce", s2[]="xbv";
cout<<"2,3的最大值是:"<<Max(3,2)<<endl;
cout<<"c,d的最大值是:"<<Max(c,d)<<endl;
cout<<Max("xbv","xyce")<<endl;
cout<<Max(s1,s2)<<endl;
system("pause");
}
/*
Expand Down

0 comments on commit 8cdadc9

Please sign in to comment.