I've got the following program:
#include<stdio.h>
template<class T> void f(T t) {
t += 1;
}
template<class T> void g(T &t) {
t += 10;
}
int main()
{
int n=0;
int&i=n;
f(i);
g(i);
printf("%d\n",n);
return 0;
}
I expect that because i
is a reference to n
, so I expect that the template function f
should get int&
for template type T
. But in fact it doesn't. The output of the program is 10
, not 11
as I expected.
So my question is, for f
, why T
matches int
but not int&
of variable i
? What's the rule behind here?
Thanks.