回顾一下前面学习到的知识,在 C++ 中,对于给定的函数名,可以有非模板函数、模板函数、显示具体化模板函数以及它们的重载版本,在调用函数时,显示具体化优先于常规模板,而非模板函数优先于显示具体化和常规模板。
#include#include using namespace std; typedef struct{ string name; int age; float score; } STU; //函数模板 template const T& Max(const T& a, const T& b); //函数模板的显示具体化(针对STU类型的显示具体化) template<> const STU& Max (const STU& a, const STU& b); //重载<< ostream & operator<<(ostream &out, const STU &stu); int main(){ int a = 10; int b = 20; cout< const T& Max(const T& a, const T& b){ return a > b ? a : b; } template<> const STU& Max (const STU& a, const STU& b){ return a.score > b.score ? a : b; } ostream & operator<<(ostream &out, const STU &stu){ out<



