(The following is thanks to dribeas) The compiler is not allowed to make implicit type conversions during template deduction, so by passing a complex with T being double, and then another T being int, when trying to match the function treating T as double causes the second argument to mis-match, and vice-versa.

For what you want to work, it would have to have a function defined similar to this:

I think its because complex is a class and the * is overloaded for that class, its not a primitive so it doesn't follow casting rules in the compiler
–
ldogOct 29 '09 at 5:58

Thanks, I've corrected the mistake about ambiguity, and my failure to code the operator correctly. (Should have done the second, but the first is a lesson to me.)
–
GManNickGOct 29 '09 at 7:03

The implementation of the operator you initially provided was not incorrect, just improvable (and in a regular project the difference would be rather small).
–
David Rodríguez - dribeasOct 29 '09 at 7:16

To me, if it's improvable it's not correct. I usually do code my operators like that, so I'd consider it a mistake.
–
GManNickGOct 29 '09 at 7:18

"The compiler is not allowed to make implicit type conversions during template deduction" is the part that I missed. Everybody involved, thanks for the answer.
–
Jitse NiesenOct 29 '09 at 20:08

std::complex<T>'s operators are defined to take as their arguments other complex<T> instances. The route from an int via a double to a complex<double> is just marginally too contorted / convoluted for the C++ language to follow it according to the standard (and with the huge complications already arising from free-wheeling conversions and cohercions it's hard to criticize that aspect of the standard). I guess the super-special case of complex<double> allowing uncasted ints as operands to its operators was just not deemed frequent and important enough to warrant specifying template specializations for that extremely individual case, considering how trivially easy it is for the programmer to cast the int to double when that's what they actually want!-)