operator是C#、C++和pascal的關(guān)鍵字,它和運(yùn)算符一起使用,表示一個(gè)運(yùn)算符函數(shù),理解時(shí)應(yīng)將operator=整體上視為一個(gè)函數(shù)名。
中文名Operator
屬于C++的關(guān)鍵字
用法運(yùn)算符一起使用
表示一個(gè)運(yùn)算符函數(shù)
關(guān)鍵字這是C++擴(kuò)展運(yùn)算符功能的方法,雖然樣子古怪,但也可以理解:一方面要使運(yùn)算符的使用方法與其原來(lái)一致,另一方面擴(kuò)展其功能只能通過(guò)函數(shù)的方式(c++中,“功能”都是由函數(shù)實(shí)現(xiàn)的)。
在symbian os c++中,返回const TUint&給描述符數(shù)據(jù)的一個(gè)指定的單個(gè)數(shù)據(jù)項(xiàng)。使用operator[]在描述符上循環(huán)的代價(jià)是昂貴的;替代的方法是考慮使用C++算數(shù)指針和TDesc::Ptr()。
operator在.Net中的應(yīng)用,在.Net中自身的狀態(tài)機(jī)制都有現(xiàn)成的操作集合的范本,像需要Add +=;需要Rmove -=;讓軟件開發(fā)者在操作的時(shí)候更簡(jiǎn)潔些,使用可重載操作的時(shí)候,更“不拘一格”;代碼如:
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;}}
}
定義運(yùn)算可以定義運(yùn)算符,讓程序比較簡(jiǎn)潔。
來(lái)一個(gè)比較丑的高精加定義
1operator+(a,b:sz)c:sz;
2vari,ni:longint;
3begin
4fillchar(c,sizeof(c),0);
5ni:=a[0];
6ifni<b[0]thenni:=b[0];
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.司機(jī)
3.接線員
He dialed the operator.
他撥通了接線員。
4.施行手術(shù)的醫(yī)生
5.(企業(yè))經(jīng)營(yíng)者
6.精明圓滑的人
7.【數(shù)】(運(yùn))算子,算符
8.旅行社計(jì)調(diào)人員
參考資料本文發(fā)布于:2023-06-05 17:15:36,感謝您對(duì)本站的認(rèn)可!
本文鏈接:http://www.newhan.cn/zhishi/a/92/207592.html
版權(quán)聲明:本站內(nèi)容均來(lái)自互聯(lián)網(wǎng),僅供演示用,請(qǐng)勿用于商業(yè)和其他非法用途。如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除。
本文word下載地址:Operator(計(jì)算機(jī)術(shù)語(yǔ)).doc
本文 PDF 下載地址:Operator(計(jì)算機(jī)術(shù)語(yǔ)).pdf
| 留言與評(píng)論(共有 0 條評(píng)論) |