W
WQ
Orginally I post this question on gamedev.net, but no useful answers,
so hope I can get help here (and seems here should be a better place
for C++ questions).
According to C++ standard 2003,
14.8.2.1, paragraph 2, the last sentence,
"If P is a reference type, the type referred to by P is used
for type deduction."
Does it mean that, if a function template takes a T & as input,
T is always be used to deduce?
For example,
template <typename T>
void myFunction(T n) { ............ }
..................
int & a = anotherIntVariable;
myFunction(a);
T is deduced as int, not int &, am I right? Does the standard mean
like that?
And my more question, can "a" be deduced as int & instead of int?
Is it possible?
From the standard, I guess not possible.
Any historical or theoretical reason that reference type
can't be deduced? Maybe because reference can't live without
the real type it references to?
so hope I can get help here (and seems here should be a better place
for C++ questions).
According to C++ standard 2003,
14.8.2.1, paragraph 2, the last sentence,
"If P is a reference type, the type referred to by P is used
for type deduction."
Does it mean that, if a function template takes a T & as input,
T is always be used to deduce?
For example,
template <typename T>
void myFunction(T n) { ............ }
..................
int & a = anotherIntVariable;
myFunction(a);
T is deduced as int, not int &, am I right? Does the standard mean
like that?
And my more question, can "a" be deduced as int & instead of int?
Is it possible?
From the standard, I guess not possible.
Any historical or theoretical reason that reference type
can't be deduced? Maybe because reference can't live without
the real type it references to?