The code compiles when the template parameter is qualified with const, like so:
template<typename T>
T increase (const T& l) {
return l+1;
}
But it does not compile without const:
template<typename T>
T increase (T& l) {
return l+1;
}
The compiler says:
“error: no matching function for call to ‘increase’”
My main:
int main() {
std::cout << increase<int>(1);
}
Why does “T& l” need to be const?