我正在学习模板,在这里我找到了这个例子:
template <typename T, int size>
void print(StaticArray<T, size> &array)
{
for (int count = 0; count < size; ++count)
std::cout << array[count] << ' ';
}
template <int size>
void print(StaticArray<char, size> &array)
{
for (int count = 0; count < size; ++count)
std::cout << array[count];
}第二个print函数为什么工作,即使它有non-type参数size,以及为什么它是完全模板专业化。
发布于 2017-10-10 05:13:07
不,这不是专门化,而是采用不同模板参数的函数模板重载。
正如您所说的,第二个重载仍然有一个模板参数,所以它不是一个完全的专门化。函数模板不允许使用部分专业化;它只适用于类模板。
https://stackoverflow.com/questions/46658927
复制相似问题