On Aug 13, 2010 at 13:14, Klaus Darilion <klaus.mailinglists(a)pernau.at> wrote:
Am 13.08.2010 11:11, schrieb Andrei Pelinescu-Onciul:
The '+' operator is special in the sense
that it converts its right
operand to the type of the left operand and the result also has the type
of the left operand. The other operators force conversion
and always have a fixed return type (e..g '*' converts both of its
operands to int and always returns int).
More examples:
"1" + 2 = "12"
1 + "2" => error
"1" + "2" = "12"
"1" * 2 => error
1 * "2" => error
"1" * "2" => error
Why are these errors? You said "The other operators force conversion"
Sorry I should have said "expects and converts only if '+' and target
type is string". strings are never converted to integers unless an
explicit cast is used (e.g. (int)"1").
Andrei