• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            doing5552

            記錄每日點滴,不枉人生一世

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              73 Posts :: 0 Stories :: 94 Comments :: 0 Trackbacks

            公告

            常用鏈接

            留言簿(24)

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 455263
            • 排名 - 48

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            自定義類
            class arc {
            ……
            bool operator<(const arc& b) const;

            }

            用容器如vector,deque存放arc對象,再其上使用stl的algrithms中的sort算法:
            sort(arcVector.begin(),arcVector.end());

            方法中需要使用“<”作比較操作,故需要重載operator<
            簡單重載 bool operator(arc&);
            很可能報錯:
            /usr/include/c++/4.2/bits/stl_algo.h:100: 錯誤: no match 為‘operator<’在‘__b < __c’
            主要是缺少const的限定(兩個都需要)。
            否則有錯:
            /usr/include/c++/4.2/bits/stl_algo.h:91: 錯誤: 將‘const arc’作為‘bool arc::operator<(const arc&)’的‘this’實參時丟棄了類型限定

            分析知道linux中stl下對C++的類型安全約束很強,const保證導入對象和自身對象都不能被修改。
            而stl的sort操作確實不需要修改比較的對象,也不應該被修改,故強制使用的自定義operator<需要兩個const限制比較的兩個對象。

            使用friend方法:
            friend bool operator<(const arc&, const arc&);

            兩種錯誤:
            1.friend bool operator<(const arc&, const arc&) const;
            錯誤: non-成員函數(shù)‘bool operator<(const arc&, const arc&)’不能擁有 cv 限定符

            2.bool operator<(const arc&, const arc&) [const]
            錯誤: ‘bool arc::operator<(const arc&, const arc&) const’帶且僅帶 1 個實參
            posted on 2011-02-15 17:32 doing5552 閱讀(2556) 評論(0)  編輯 收藏 引用
            亚洲va中文字幕无码久久不卡| 无码人妻少妇久久中文字幕| 久久国产免费观看精品3| 国产精品久久久久aaaa| 国产午夜精品理论片久久| 中文字幕人妻色偷偷久久| 国产精品18久久久久久vr | 久久香蕉国产线看观看99| 久久青青草原综合伊人| 精品综合久久久久久97| 国产AV影片久久久久久| 久久亚洲欧美国产精品| 久久强奷乱码老熟女网站 | 一本久久久久久久| 伊人色综合久久天天人手人婷| 久久夜色tv网站| 久久精品aⅴ无码中文字字幕重口| 久久国产乱子伦精品免费午夜| 色欲综合久久躁天天躁蜜桃| 欧美久久亚洲精品| 国内精品伊人久久久久影院对白 | 久久97久久97精品免视看| 久久国产色AV免费观看| 一本一道久久综合狠狠老| 欧美成a人片免费看久久| 国内精品欧美久久精品| 国产精品激情综合久久| 91精品国产高清久久久久久国产嫩草| 99久久精品免费看国产一区二区三区| 久久人妻少妇嫩草AV蜜桃| 国产福利电影一区二区三区久久久久成人精品综合 | 久久精品国产亚洲AV无码娇色| 麻豆精品久久久久久久99蜜桃| 久久精品中文字幕第23页| 国内精品欧美久久精品| 久久99精品久久久久久水蜜桃 | 亚洲va久久久噜噜噜久久天堂| AV无码久久久久不卡蜜桃| 青青草原精品99久久精品66| 狼狼综合久久久久综合网| 久久国产精品99精品国产987|