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

前端 未结 3 569
情歌与酒
情歌与酒 2021-01-04 09:06

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,

3条回答
  •  佛祖请我去吃肉
    2021-01-04 09:09

    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.

提交回复
热议问题