[fpc-pascal] why can't we define class operator for old fashion object type, but ok for 'advanced record' type?

Sven Barth pascaldragon at googlemail.com
Sun Aug 19 10:11:53 CEST 2018


Ryan Joseph <ryan at thealchemistguild.com> schrieb am Sa., 18. Aug. 2018,
19:38:

>
>
> > On Aug 17, 2018, at 7:19 PM, Sven Barth via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> > However for classes there is the problem of temporary variables. Take a
> := b + c + d. That is essentially compiled as t := b + c; a := t + d. The
> compiler does not know whether the operator creates an instance or not
> (yes, there are circumstances when it can know that, but for the general
> case it can't) and thus this would potentially lead to memory leaks.
> >
>
> I’m must be confused because classes already have operator overloads,
> they’re just in global scope outside of the class itself. Don’t all the
> same rules apply if the syntax is put inside the class (like in records)
> just the scope rules change?
>

Delphi does not have global operator overloads and in FPC the problem I
mentioned indeed happens with global overloads. It's just that not many
people use global overloads for classes (especially now that generics are
used more).

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180819/f7bc098d/attachment.html>


More information about the fpc-pascal mailing list