Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-07

operator ovelroading documentation

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hans-Peter Diettrich
to Martin
Show quoted text 6 lines
http://www.freepascal.org/docs-html/ref/refse68.html#x164-17400012.3 the first ( of several) examples on that page is > Var > C,Z : Complex; // New type complex

What's "new" with that type? Where is it declared?

Show quoted text 11 lines
> begin > Z:=C; // assignments between complex types. > end; > > The following assignment operator would have to be defined: > > Operator := (C : Complex) z : complex; However, the compiler rejects that with: project1.lpr(10,38) Error: Impossible to overload assignment for equal types

The example doesn't declare an new type "Complex", so that most probably that already existing type already *has* operators - and accordingly the compiler doesn't allow to redefine these operators.

What happens if you declare an really new type, e.g. TNewComplex, and try again with this type?

It looks to me as if that page should be revised. A reference to the already defined Complex operators should be added, and the following sections may need an update as well, in detail the "experimental solution" also may have changed in the meantime.

DoDi

Reply by email

Martin
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 9 lines
Martin schrieb: > http://www.freepascal.org/docs-html/ref/refse68.html#x164-17400012.3 > > the first ( of several) examples on that page is > >> Var >> C,Z : Complex; // New type complex What's "new" with that type? Where is it declared?

It's not about the type. It applies to just any type. declare your own "Complex" or use "TFoo"

Show quoted text 10 lines
>> >> Operator := (C : Complex) z : complex; > > However, the compiler rejects that with: > project1.lpr(10,38) Error: Impossible to overload assignment for > equal types The example doesn't declare an new type "Complex", so that most probably that already existing type already *has* operators - and accordingly the compiler doesn't allow to redefine these operators.

See above, same for TFoo.

Reply by email