#2
sunjiji20062010-12-07 09:47
|
#include <iostream>
using namespace std;
template<typename T>
T const& max(T const& a, T const& b){
return a < b ? b : a;
}
template<typename T> //函数模版重载
T* const& max(T* const& a, T* const& b){
return *a < *b ? b : a;
}
const char* const& max(const char* const& a, const char* const& b){
//普通函数重载
return strcmp(a,b) < 0 ? b : a;
}
main(){
int ia=3, ib=7;
char *s1=”hello”, *s2=”hell”;
cout<<*max(&ia, &ib)<<”\n”; // match the second template
cout<<max(s1, s2)<<”\n”; // match the max function
cout<<max(ia, ib)<<”\n”; // match the first template
}