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

Ryan Joseph ryan at thealchemistguild.com
Sat Aug 18 19:37:46 CEST 2018



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

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list