- Expert Delphi
- Pawe? G?owacki
- 157字
- 2021-07-02 20:44:24
Operator overloading
Your code can be more readable with operator overloading. You cannot overload the meaning of arbitrary operators in Object Pascal, only the built-in operators. You can also implement implicit conversion operators that make it possible to assign different types to a given type and define what would happen during the assignment. You can also define comparison operators to define the results of the built-in operators, =,<, and >.
Operator overloading leads to more compact, more readable code. For example, Delphi comes with a System.Math.Vectors unit with different useful types such as TVector3D with useful overloaded operations, as shown in the following code snippet:
uses System.Math.Vectors; procedure DoSomeVectorMath; var A, B, C: TVector3D; begin A := TVector3D.Create(1,2,4); B := TVector3D.Create(2,3,1); C := A + B; // ...
Another good example is the TAlphaColorF record type defined in System.UITypes, which defines different operations on colors using real numbers.
Operator overloading cannot be used with class types, only with records.
- C++程序設計教程
- LaTeX Cookbook
- Python數(shù)據(jù)可視化:基于Bokeh的可視化繪圖
- C/C++算法從菜鳥到達人
- Java Web及其框架技術(shù)
- Oracle 18c 必須掌握的新特性:管理與實戰(zhàn)
- AIRIOT物聯(lián)網(wǎng)平臺開發(fā)框架應用與實戰(zhàn)
- RESTful Java Web Services(Second Edition)
- Learning Modular Java Programming
- Red Hat Enterprise Linux Troubleshooting Guide
- Natural Language Processing with Python Quick Start Guide
- Training Systems Using Python Statistical Modeling
- 深入分析GCC
- Java從入門到精通(視頻實戰(zhàn)版)
- 用Python動手學統(tǒng)計學