我对下面的模板行为感到困惑,因为它在空的尖括号中编译正常(没有参数的模板),由于语法上,template<>保留用于标记显式模板特化。
template <typename T> void add(T a, T b) { }
int main() {
add<>(10, 3); // compiles fine since both parameters are of same data type
add<>(10, 3.2); // Error: no matching function for call to add(int, double)
}
在上述情况中,模板参数是否真的是可选的?