根据模板参数的不同,输入相同数组,类型参数的推断结果不同
template
void test1(const T1 &arr)
{
T1 t1;
cout << typeid(arr).name() << endl;
cout << typeid(t1).name() << endl;
}
template
void test2(const T2(&arr)[size])
{
T2 t2;
cout << typeid(arr).name() << endl;
cout << typeid(t2).name() << endl;
}
int main()
{
int arr[3] = { 0 };
test1(arr);
test2(arr);
}
输出结果如下: