为什么int[]不能转换为T*&?

N.Y*_*Y.C 4 c++ templates type-conversion

template <class T>\nvoid func(T*& a)\n{\n\n}\n\nint main()\n{\n    int a[5];\n    func(a); // <-- Error here: no matching function for call to \xe2\x80\x98func(int [5])\xe2\x80\x99\n\n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

为什么int[]不隐式转换为int*以便可以匹配模板函数?

\n

Mil*_*nek 6

存在从int[5]to 的隐式转换int*,但 anint[5]不是 an int*。因此没有int*可供参考int*&的参数。func<int>

int这种情况与尝试将 an 传递给需要 a 的函数没有什么不同float&。仅仅因为 anint可以隐式转换为 afloat并不意味着 anint 就是a float。完全相同的事情也适用于int[5]int*。仅仅因为一个可以隐式转换为另一个并不意味着它们是同一件事。