You cannot pass an array to a function. You have options to approximate it:
- reference to a raw array
- std::array
- std::vector
For maximum efficiency, you do not want to copy an array. That's why arrays decay to pointers in the first place (though it was inherited from C and there are better ways to accomplish the same or similar behavior that is more type-safe.) If you want to keep the type without decay, you must pass a reference to the array, or to an object containing such an array.
// pass reference to a raw array (Array of N elements of type T)
template <typename T, int N>
void foo1(T(&arrayArg)[N])
{
std::cout << arrayArg[0] << "\n";
}
Given the code you initially used in your question, I suspect the above is what you were looking for. However consider the alternatives too, because arrays are not a very robust data type in c++ and there are better options for general code.
// pass reference to std::array
template <typename T, int N>
void foo2(std::array<N, T> const & arrayArg)
{
std::cout << arrayArg[0] << "\n";
}
The std::array is a class that contains a raw array underneath, but has more of a C++ friendly interface and is not subject to decaying.
// pass reference to std::vector
template <typename T>
void foo2(std::vector<T> const & vecArg)
{
std::cout << vecArg[0] << "\n";
}
Vector is dynamically sized, and is getting farther away from the raw array you started with, but is the building block of many, many c++ data structures and algorithms and should be one of the first things you consider in most cases.