1. 重载模板语法形式如下所示
template <typename T>
string debug_rep(const T &t)
{
ostringstream ret;
ret<<t;
return ret.str();
}
当存在多个模板实例化结果时,编译器选择最准确的和最特例化的版本(如非模板函数)
2. 可变参数模板
参数个数不止一个
template<typename T>
ostream &print(ostream &os,const T &t)
{
return os<<t;
}
template<typename T,typename ...Args>
ostream &print(ostream &os,const T &t,const Args&...rest)
{
os<<t<<'\\'}