[fpc-devel] Operator overloading question: Impossible to overload assignment for equal types. Why?
Sven Barth
pascaldragon at googlemail.com
Thu Apr 25 14:16:49 CEST 2024
Bart via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am Do., 25.
Apr. 2024, 11:48:
>
> > 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
>
> So, I would have to declare something like this?
>
> class operator TArr.Copy(constref aSrc: TArr; var aDst: TArr);
> begin
> aDst.A := Copy(aSrc.A);
> end;
>
> And then in my example:
>
> R1.A := [1,2,3];
> R2 := R1;
> --> R2.A will be (1,2,3), and changing that will not affect R1.A anymore
>
Correct.
> Sounds like a nice feature to have (in 3.4).
>
Management operators are already part of 3.2.x (
https://wiki.freepascal.org/FPC_New_Features_3.2.0#Management_operators_for_record_types
). Or did I misunderstand your remark? 🤔
> I'll write some tests to get familiar with this and if I don't forget
> I'll write a simple example in the wiki (there's a ToDo for that
> currently).
>
Please do. 😊
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20240425/a9b619e0/attachment.htm>
More information about the fpc-devel
mailing list