選擇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

          主站蜘蛛池模板: 旌德县| 绵阳市| 龙井市| 永德县| 柳林县| 溧阳市| 名山县| 大厂| 铜川市| 花莲县| 清远市| 泽库县| 鄯善县| 海林市| 泊头市| 定襄县| 郑州市| 鄢陵县| 颍上县| 济阳县| 铁岭县| 宜章县| 集贤县| 蒙自县| 孟州市| 金湖县| 峨山| 白玉县| 西乌珠穆沁旗| 松阳县| 彭州市| 汾西县| 西乡县| 原平市| 老河口市| 区。| 东乡| 横峰县| 康定县| 眉山市| 保山市|