64,652
社区成员
发帖
与我相关
我的任务
分享
template<typename T>
struct comp_impl
{
int operator()(T lhs, T rhs) {
if(lhs==rhs)
return 0;
if(lhs>rhs)
return 1;
if(lhs<rhs)
return -1;
}
};
template<typename T>
struct comp_impl<T*>
{
int operator()(T* lhs, T* rhs) {
return comp_impl<T>()(*lhs, *rhs);
}
};
template<typename T> int compare(T* lhs, T* rhs) {
return comp_impl<T>()(*lhs, *rhs);
}
template<typename T> int compare2(T lhs, T rhs) {
if(lhs==rhs)
return 0;
if(lhs>rhs)
return 1;
if(lhs<rhs)
return -1;
}
template<typename T> int compare2(T* lhs, T* rhs) {
return compare2<T>(*lhs, *rhs);
}
int _tmain(int argc, _TCHAR* argv[])
{
double x1 = 10, y1 = 11;
double *x2 = &x1, *y2 = &y1;
double **x3 = &x2, **y3 = &y2;
double ***x4 = &x3, ***y4 = &y3;
compare(x4, y4);
compare2(x4, y4);
}
template<typename T> int compare2(T lhs, T rhs) {
if(lhs==rhs)
return 0;
if(lhs>rhs)
return 1;
if(lhs<rhs)
return -1;
}
template<typename T> int compare2(T* lhs, T* rhs) {
return compare2(*lhs, *rhs);
}