• <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)

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 455403
            • 排名 - 49

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            自定義類
            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 閱讀(2557) 評論(0)  編輯 收藏 引用
            99麻豆久久久国产精品免费| 久久久中文字幕日本| 粉嫩小泬无遮挡久久久久久| 久久99国产精品久久99| 国产午夜精品久久久久九九| 97久久婷婷五月综合色d啪蜜芽| 久久成人国产精品| 色偷偷88欧美精品久久久| 久久精品国产亚洲AV高清热| 久久午夜福利电影| 久久久久亚洲av无码专区喷水| 久久成人永久免费播放| 久久香蕉超碰97国产精品| 久久久久国产精品三级网| 潮喷大喷水系列无码久久精品 | 亚洲国产日韩综合久久精品| 午夜天堂精品久久久久| 伊人 久久 精品| 久久亚洲电影| 国内精品久久久久久久久电影网| 久久久久综合中文字幕| 久久精品国产亚洲AV大全| 伊人色综合久久天天人守人婷| 麻豆成人久久精品二区三区免费| 久久综合精品国产一区二区三区 | 国产精品久久久久久影院| 久久久久亚洲精品日久生情| 久久久噜噜噜久久| 激情久久久久久久久久| 久久久久久亚洲AV无码专区| 久久久久国产精品人妻| 亚洲国产高清精品线久久| 久久本道久久综合伊人| 国产精品免费久久| 亚洲精品高清国产一久久| 99精品久久久久久久婷婷| 久久精品男人影院| 亚洲国产成人久久综合一| 精品久久久久久综合日本| 久久精品国产99国产精品澳门| 精品久久久久久中文字幕|