What kinds of operator overloads does Delphi support?

后端 未结 2 465
春和景丽
春和景丽 2020-12-31 04:48

I wonder what sort of operator overloads are possible (and with what version of Delphi)? Thanks to Hallvard\'s great write-up on operator overloading, I know of :

2条回答
  •  甜味超标
    2020-12-31 05:52

    I just put my notes online of a session on nullable types with operator overloading that I gave during a few conferences.

    It now contains a table of the operators, the names and what works/doesn't work. WordPress initially malformed that table, but I managed to restore it.

    You can also download the full set of slides and source code demos.

    In short:

    • The documentation (even the DocWiki) is not complete, and note reliable
    • You cannot overload the bitwise not operator, as BitwiseNot is not supported by the compiler. You have to overload the logical not operator in stead.
    • Overload operators pairwise where applicable
    • Be aware of existing operators
    • Be very careful when implementing implicit operators

    Hope this helps you. Let me know if you need more info: I have done quite a bit of production work with operator overloading.

    --jeroen

提交回复
热议问题