Why can't I return the first element of an array in a template?

Viewed 731

Consider:

#include <iostream>

template <typename T> T getArray( T &arr ) {
    return *arr;
}

int main() {

    int a[] = {5, 3, 6};

    std::cout << getArray(a);

}

It's suppose to print the first element in the array but it is not not working. Why is that?

It gives me the error:

error: no matching function for call to 'getArray(int [3])'
4 Answers
Related