69,371
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
template <int N=1,typename T>
class Compare
{
public:
inline bool operator()(const T& a,const T& b)const;
};
template <int N,typename T>
bool Compare<N,T>::operator()(const T& a,const T& b)const
{
if(N > 0) return a > b;
if(N < 0) return a < b;
return a == b;
}
int main()
{
int a=18;
int b=10;
if(Compare<>()(a,b))
/* 此处的模板实参为什么不能省略?第一个是默参,第二个可通过函数实参推导?只写第一个也不行,必须全写出才能正确*/
std::cout<<"a > b"<<std::endl;
return 0;
}