Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't operator overloading available for classes in Delphi?

I've always wondered about this for a bit, but why is operator overloading not available for classes in Delphi?

I remember reading an answer once while on the run, and it said it would come in conflict with something, but I can't remember much. As far as I can tell, only the implicit operator may cause a bit of problems since classes are stored on the heap and assigning is actually a copy of the heap address (basically copying pointers).

like image 303
Cloud737 Avatar asked Jan 19 '10 01:01

Cloud737


1 Answers

Close. It's because objects are reference types and the memory is managed manually. So if you said myResult := myObject1 + myObject2 + myObject3;, you'd have to create an intermediate object somewhere in there, and there's no code to free it, so you get memory leaks.

like image 55
Mason Wheeler Avatar answered Sep 21 '22 18:09

Mason Wheeler