#include <iostream>
template <typename T>
T max(T x, T y)
{
    return x > y ? x : y;
}

//函数模板特化
template <>
const char* max(const char* x, const char* y){
    return strcmp(x, y) > 0 ? x : y;
}

int main(){
    std::cout << max(1, 2);
    std::cout << max("hello", "world");
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2021-11-11
  • 2022-01-02
  • 2021-12-24
  • 2021-12-06
  • 2021-11-06
猜你喜欢
  • 2022-03-08
  • 2021-07-30
  • 2022-12-23
  • 2021-12-24
  • 2021-09-09
  • 2021-10-21
  • 2022-12-23
相关资源
相似解决方案