template
void f(T a, const T& b)
{
++a; // ok
++b; // also ok!
}
template
void g(T n)
{
f(n, n);
}
int
I know that there is already an accepted answer which is correct but just to add to it a little bit, even outside the realm of templates and just in function declarations in general...
( const T& )
is not the same as
( const T )
In your example which matches the first, you have a const reference. If you truly want a const value that is not modifiable remove the reference as in the second example.