我正在学习 C++ 模板概念。我不明白以下内容。
#include <iostream>
#include <typeinfo>
using namespace std;
template <typename T>
T fun(T& x)
{
cout <<" X is "<<x;
cout <<"Type id is "<<typeid(x).name()<<endl;
}
int main ( int argc, char ** argv)
{
int a[100];
fun (a);
}
我在尝试什么?
1) T 乐趣 (T & x)
这里 x 是一个引用,因此不会将“a”衰减为指针类型,但是在编译时,我收到以下错误。
error: no matching function for call to ‘fun(int [100])’
当我尝试非参考时,它工作正常。据我了解,数组已衰减为指针类型。