Delphi支持哪些运算符重载? [英] What kinds of operator overloads does Delphi support?
问题描述
感谢哈佛对操作员重载的伟大写作,我知道:
- 添加(左,右:类型):类型(对于'+'运算符)
- 减法(左,右:类型):类型(对于' - '运算符)
- 乘法(左,右:类型):类型*'运算符)
- 分割(左,右:类型):类型(对于'/'运算符)
- 隐式(aValue:Type) :另一个类型和
- 隐式(aValue:AnotherType):类型(用于隐式赋值:a:= b)
- 显式(aValue:Type)另一个类型和
- 显式(aValue:AnotherType):类型(对于casts的显式分配:a:= Type(b)
然而,我不知道的是'=','< =','<',''','>'和'>的名称='运算符,这些存在,从什么Delphi版本可以我使用这些?
PS:我现在仍然使用Delphi 2009,所以如果2010年提供这些,我会有另一个强大的升级参数; - )
其实我自己找到了答案,但是保留问题,我可以想象人们会定期在stackoverflow上搜索这个信息; / p>
可以在这里找到关于运算符重载的官方描述: http://docwiki.embarcadero.com/RADStudio/en/Operator_Overloading_(Delphi)
主要是我正在看的被命名为:
- 等于'='比较:等于(a:type;对于'<>'比较:NotEqual(a:type; b:type):Boolean;
- GreaterThan,for'>'比较:GreaterThan(a:type; b:type)Boolean;
- GreaterThanOrEqual,for'> ='比较:GreaterThanOrEqual(a:type; b:类型):resultType;
- LessThan,for'<'compare:LessThan(a:type; b:type):resultType;
- LessThanOrEqual ,for'< ='比较:LessThanOrEqual(a:type; b:type):resultType;
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 :
- Add(Left, Right: Type): Type (for the '+' operator)
- Subtract(Left, Right: Type): Type (for the '-' operator)
- Multiply(Left, Right: Type): Type (for the '*' operator)
- Divide(Left, Right: Type): Type (for the '/' operator)
- Implicit(aValue: Type): AnotherType and
- Implicit(aValue: AnotherType): Type (for implicit assignments : a := b)
- Explicit(aValue: Type): AnotherType and
- Explicit(aValue: AnotherType): Type (for explicit assignmetns of 'casts' : a := Type(b)
However, what I don't know are the names for the '=', '<=', '<', '<>', '>' and '>=' operators. Do these exist, and from what Delphi version can I use these?
PS: I still use Delphi 2009 at the moment, so I would have another strong upgrade-argument if 2010 offers these ;-)
Actually, I found the answer to this myself, but kept the question as I can imagine people will search for this information regularly on stackoverflow;
The official description on operator overloaders can be found here : http://docwiki.embarcadero.com/RADStudio/en/Operator_Overloading_(Delphi)
Mainly, the ones I was looking for are named:
- Equal, for '=' comparison : Equal(a: type; b: type) : Boolean;
- NotEqual, for '<>' comparison : NotEqual(a: type; b: type): Boolean;
- GreaterThan, for '>' comparison : GreaterThan(a: type; b: type) Boolean;
- GreaterThanOrEqual, for '>=' comparison : GreaterThanOrEqual(a: type; b: type): resultType;
- LessThan, for '<' comparison : LessThan(a: type; b: type): resultType;
- LessThanOrEqual, for '<=' comparison : LessThanOrEqual(a: type; b: type): resultType;
这篇关于Delphi支持哪些运算符重载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!