为什么下面的代码有效为什么模板必须在每个使用函数之前声明?
template<class T>
T AddThree(T input)
{
return input + 3;
}
template<class T> // If I remove this line it won't compile
T SubtractThree(T input)
{
return input - 3;
}
但是,如果我注释掉该行表示,它不会编译?编译器在第一次声明时如何不知道template<class T>
(就像在文件主体中声明的其他东西一样)?
谢谢!我没有想过,声明模板的行实际上只是函数声明的一部分:) – Kvothe 2015-02-23 19:44:17