On Jul 25, 7:22 am, pikalaw <pika...@gmail.com> wrote:
On Jul 24, 11:14 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
[...]
It seems that implicit type-conversion is only allowed with
non- template functions. Had I declared
complex<long> operator*(long a, const complex<long> &z)
then the expression '2 * k' compiles fine.
However, with template version of functions, implicit
type-conversion is not done.
BTW, is this behavior in the C++ standard? Or one of those
unspecified, implementation-dependent behavior?
It's the required behavior, according to the standard. You're
confusing two separate issues: operator overload resolution and
template type deduction. A function template is NOT a function,
and is not considered directly by operator overloading. If
there is a function template in scope, the compiler will try to
deduce its arguments, in order to instantiate it; if this
succeeds, the instantiated instance (which is a function) will
be added to the overload set, to be considered by overload
resolution. Very few conversions are considered (cv-qualifier
conversions, I think, and not much else) for template argument
deduction, because otherwise, one would end up with far too many
possibilities.
One of them (it's actually worthwhile to know about in order to write templates