template <class T>
void func(T*& a)
{
}
int main()
{
int a[5];
func(a); // <-- Error here: no matching function for call to ‘func(int [5])’
return 0;
}
why int[] is not implicitly converted to int* so that it can match template functions?
There is an implicit conversion from int[5] to int*, but an int[5] is not an int*. Thus there is no int* for the int*& parameter of func<int> to reference.
This situation is no different from trying to pass an int to a function expecting a float&. Just because an int can be implicitly converted to a float doesn't mean an int is a float. The exact same thing applies to int[5] and int*. Just because one can be implicitly converted to the other doesn't mean that they are the same thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With