選擇java 進入自由開放的國度

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

          ++運算符重載問題

          簡單探討了++運算符的問題:

          ?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論成敗 以架構論英雄 閱讀(470) 評論(0)  編輯  收藏 所屬分類: Reading

          主站蜘蛛池模板: 长葛市| 祥云县| 靖宇县| 泸定县| 五大连池市| 余干县| 茶陵县| 毕节市| 那曲县| 渭源县| 政和县| 富阳市| 昌邑市| 伊金霍洛旗| 卢湾区| 青神县| 安图县| 康定县| 太原市| 韶关市| 和田市| 泗阳县| 沁阳市| 定边县| 凉城县| 天柱县| 府谷县| 巴里| 长葛市| 金平| 禄劝| 陇南市| 清水河县| 光山县| 通道| 建水县| 文昌市| 电白县| 通许县| 柘荣县| 鸡东县|