[fpc-devel] class operator overloads

Sven Barth pascaldragon at googlemail.com
Mon Jun 10 20:21:54 CEST 2019


Ryan Joseph <genericptr at gmail.com> schrieb am Mo., 10. Juni 2019, 16:26:

>
>
> > On Jun 10, 2019, at 9:31 AM, Sven Barth via fpc-devel <
> fpc-devel at lists.freepascal.org> wrote:
> >
> > The +-operator is not defined internally thus it is allowed to be
> overloaded. (is it really that hard to understand? If you can use an
> operator in code without declaring an operator overload then this operator
> is internal and not allowed to be overloaded).
> >
>
> I get what you mean but I had no idea := with the destination variable was
> an operator.


There exist only two assignment operators, namely "Implicit" (aka := in
mode ObjFPC) and "Explicit" both taking a single argument. Introducing a
binary operator does not change that the operator is forbidden for classes.


> I just tried this right now and I didn’t an error but it was indeed not
> overloaded and never got called. A bug?
>
> operator := (left, right: TObject): TObject;
> begin
>   writeln('custom :=');
> end;
>
> var
>   c: TObject;
> begin
>   c := TObject.Create;
> end.
>

Did you try with trunk? Cause I fixed something related to that a few weeks
ago.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190610/4a70f1f2/attachment.html>


More information about the fpc-devel mailing list