[fpc-devel] operator ovelroading documentation

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sun Jul 31 16:14:00 CEST 2011


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?

>> 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




More information about the fpc-devel mailing list