• <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++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              73 Posts :: 0 Stories :: 94 Comments :: 0 Trackbacks

            公告

            常用鏈接

            留言簿(24)

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 455274
            • 排名 - 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-成員函數‘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)  編輯 收藏 引用
            久久久久精品国产亚洲AV无码| 久久中文字幕人妻丝袜| 韩国免费A级毛片久久| 久久99国产精品99久久| 国产ww久久久久久久久久| 久久久久久久久久免免费精品| 亚州日韩精品专区久久久| 奇米综合四色77777久久| 久久噜噜电影你懂的| 无码国内精品久久综合88| 精品综合久久久久久97超人| 日韩久久久久中文字幕人妻 | 久久青青草原精品国产| 久久―日本道色综合久久| 久久国产AVJUST麻豆| 国产成人无码精品久久久久免费| 久久久久久久久久久| 中文字幕久久欲求不满| 久久综合给合久久狠狠狠97色69| 久久精品二区| 爱做久久久久久| 国产精品久久久福利| 人人狠狠综合久久88成人| 伊人久久大香线蕉综合网站| 国产精品日韩欧美久久综合| 俺来也俺去啦久久综合网| 亚洲AV日韩AV天堂久久| 久久91精品国产91| 亚洲国产日韩欧美久久| 久久久久国色AV免费观看| 久久精品免费观看| 久久久久夜夜夜精品国产| 久久精品www人人爽人人| 亚洲AV无码久久精品成人| 久久精品国产精品亚洲精品| 久久久久久久91精品免费观看| 久久久久成人精品无码| 久久久噜噜噜久久| 亚洲精品无码久久久| 久久精品国产2020| 久久亚洲精品中文字幕|