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

          主站蜘蛛池模板: 彭泽县| 安阳县| 天门市| 蓬安县| 哈巴河县| 宁夏| 玛沁县| 万州区| 巩义市| 三亚市| 绥江县| 游戏| 多伦县| 桦南县| 监利县| 博爱县| 修武县| 北安市| 明水县| 呼图壁县| 巴中市| 诸城市| 葫芦岛市| 汾阳市| 马尔康县| 惠来县| 上虞市| 贡觉县| 洮南市| 沐川县| 抚顺县| 乌兰察布市| 安丘市| 罗源县| 万年县| 罗山县| 兰溪市| 昌乐县| 儋州市| 洛扎县| 叙永县|