Bart via fpc-devel <fpc-devel@lists.freepascal.org> schrieb am Mi., 24.
Apr. 2024, 11:59:

> Overloading the := (assignment) operator for equal types is forbidden.
> Out of curiosity I would like to know why that is?
>

If there exists a built-in operator then overloading that operator is
forbidden to avoid confusion when what operator might be used (operators
can after all be declared *anywhere* and thus they might sometimes be used
and sometimes not depending on which unit is used).


> When you have e.g. a record definition containing a dynamic array, not
> being able to overload the assignment operator is just a PITA.
>

Then declare a Copy management operator in the record. Unlike an assignment
operator these *must* be part of the record, thus the same rules are
applied for the same type everywhere unlike for operator overloads. See
also https://wiki.freepascal.org/management_operators

Regards,
Sven
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to