選擇java 進(jìn)入自由開放的國度

          隨筆 - 49, 文章 - 3, 評論 - 154, 引用 - 1
          數(shù)據(jù)加載中……

          ++運(yùn)算符重載問題

          簡單探討了++運(yùn)算符的問題:

          ?1 #include? < iostream >
          ?2 using?namespace?std;
          ?3
          ?4 class ?temp
          ?5 {
          ?6 private ?:
          ?7 ???? int ?x?;
          ?8 public ?:
          ?9 ?temp()
          10 ? {x? = ? 5 ;}
          11 ?? /* ??void?operator?++(void)
          12 ???{
          13 ???????x++;
          14 ???}
          15 ??
          16 ?void?operator?++(?int)
          17 ???{
          18 ???????x++;
          19 ???} */

          20 ???temp & ?operator? ++ ()
          21 ??? {
          22 ??????x ++ ;
          23 ???cout? << ? " ++a " ? << ?endl;
          24 ??? return ? * this ;
          25 ???}

          26
          27 ???temp & ?operator? ++ ( int )
          28 ??? {
          29 ??????x ++ ;
          30 ???cout? << ? " a++ " ? << ?endl;
          31 ??? return ? * this ;
          32 ???}

          33 ???
          34 ??? void ?show()
          35 ??? {
          36 ?????cout? << ?x;
          37 ???}

          38 }
          ;
          39
          40 int ?main()
          41 {
          42 /*
          43 ??operator?++(void)??=>?++a;
          44 ??operator?++(int)???=>?a++;
          45 */

          46 temp?a;
          47 ++ a;?? // 只能++a,而a++就會有警告。
          48 a ++ ;
          49 a.show();
          50 ??system( " pause " );
          51 return ? 0 ;
          52 }

          53

          operator?++(void)??=>?++a;
          operator?++(int)???? =>?a++;

          ++a;? //call operator++(void)。
          a++;? //call operator++(int)

          posted on 2006-04-28 11:01 soochow_hhb 以java論成敗 以架構(gòu)論英雄 閱讀(478) 評論(0)  編輯  收藏 所屬分類: Reading

          主站蜘蛛池模板: 乡城县| 河源市| 津南区| 潞城市| 沂源县| 含山县| 南溪县| 文成县| 喜德县| 临漳县| 林芝县| 股票| 涞源县| 沾化县| 常德市| 龙州县| 腾冲县| 札达县| 忻城县| 合川市| 通城县| 丹棱县| 星子县| 乐亭县| 乌鲁木齐县| 新乡县| 浮山县| 定安县| 哈尔滨市| 平罗县| 盐源县| 建瓯市| 渭南市| 苏尼特左旗| 清徐县| 新建县| 谷城县| 出国| 高碑店市| 永修县| 广昌县|