Function template example
template<typename T, int n>
T max(T (&arr)[n])
{
T maxm = arr[0];
for(int i = 1; i <n; ++i)
if (maxm < arr[i])
maxm = arr[i];
return maxm;
}
Is arr also a type parameter like T ?
arr is a name of a function parameter. It's not a type parameter. Its type is a reference to an array of element type T and length n.
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