64,654
社区成员
发帖
与我相关
我的任务
分享
template<typename T>
bool COMPARE(const T& t1,const T& t2);
#define LP_COMPARE (*COMPARE)
bool sortIntT1(int t1,int t2,LP_COMPARE com)
{
if ((*com)(t1,t2))
{
printf("%s\n", "sfafsfsfsfffffffa");
}
else
{
printf("%s\n", "sfafffffffa");
}
return com(t1,t2);
}
bool intCom(int i1,int i2)
{
return i1>i2;
}
template<typename T,typename FUN>
bool sortIntT(const T& t1,const T& t2,FUN com)
{
if (com(t1,t2))
{
printf("%s\n", "sfafsfsfsfffffffa");
}
else
{
printf("%s\n", "sfafffffffa");
}
return com(t1,t2);
}
sortIntT(10,11,&intCom);
template<typename T>
bool COMPARE(const T& t1,const T& t2);
#define LP_COMPARE (*COMPARE)
bool sortIntT1(int t1,int t2,LP_COMPARE com) //这个函数实例化的时候,必须先将com这个模板实例化,否则,将无法对这个函数实例化,但是com的实例化缺依赖函数本身前两个参数,这个还是在执行阶段实例化的,两个函数的实例化出现了冲突,所以出错
{
if ((*com)(t1,t2))
{
printf("%s\n", "sfafsfsfsfffffffa");
}
else
{
printf("%s\n", "sfafffffffa");
}
return com(t1,t2);
}
template <class T, class Cmp>
bool Func(T const &x, T const &y, Cmp cmp)
{
return cmp(x, y);
}