声明后,模板可以像其他函数一样使用。它们的使用由命名模板和提供函数参数组成。编译器可以从函数参数类型推断出模板类型参数。例如,您可以按以下方式使用以前声明的模板:
double twicedouble( double item ) { return twice( item ); }
如果模板参数不能从函数参数类型推断出,则调用函数时必须提供模板参数。例如:
template<class T> T func(); // no function arguments int k = func<int>(); // template argument supplied explicitly