Operator

Operator

计算机术语
operator是C#、C++和pascal的关键字,它和运算符一起使用,表示一个运算符函数,理解时应将operator=整体上视为一个函数名。[1]
  • 中文名:Operator
  • 外文名:
  • 适用领域:
  • 所属学科:
  • 属于:C++的关键字
  • 用法:运算符一起使用
  • 表示:一个运算符函数

关键字

这是C++扩展运算符功能的方法,虽然样子古怪,但也可以理解:一方面要使运算符的使用方法与其原来一致,另一方面扩展其功能只能通过函数的方式(c++中,“功能”都是由函数实现的)。

在symbian os c++中,返回const TUint&给描述符数据的一个指定的单个数据项。使用operator[]在描述符上循环的代价是昂贵的;替代的方法是考虑使用C++算数指针和TDesc::Ptr()。

operator在.Net中的应用,在.Net中自身的状态机制都有现成的操作集合的范本,像需要Add +=;需要Rmove -=;让软件开发者在操作的时候更简洁些,使用可重载操作的时候,更“不拘一格”;代码如:

public class ErrorEntity

{

private IList messages=new List();

private IList codes=new List();

public static ErrorEntity operator+(ErrorEntity entity,string str)

{

entity.messages.Add(str);

return entity;

}

public static ErrorEntity operator+(ErrorEntity entity,int code)

{

entity.codes.Add(code);

return entity;

}

public static ErrorEntity operator-(ErrorEntity entity,string str)

{

entity.messages.Remove(str);

return entity;

}

public static ErrorEntity operator-(ErrorEntity entity,int code)

{

entity.codes.Remove(code);

return entity;

}

public IList Messages{get{return messages;}}

public IList Codes{get{return codes;}}

}

定义运算

可以定义运算符,让程序比较简洁。

来一个比较丑的高精加定义

1operator+(a,b:sz)c:sz;

2vari,ni:longint;

3begin

4fillchar(c,sizeof(c),0);

5ni:=a[0];

6ifni

7fori:=1tonido

8begin

9c[i]:=c[i]+b[i]+a[i];

10ifc[i]>9then

11begin

12inc(c[i+1],c[i]div10);

13c[i]:=c[i]mod10;

14end;

15end;

16ifc[ni+1]>0theninc(ni);

17c[0]:=ni;

18end.

单词

名词n.[C]

1.操作者,技工

2.司机

3.接线员

He dialed the operator.

他拨通了接线员。

4.施行手术的医生

5.(企业)经营者

6.精明圆滑的人

7.【数】(运)算子,算符

8.旅行社计调人员

相关词条

相关搜索

其它词条