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

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 454869
            • 排名 - 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 閱讀(2549) 評論(0)  編輯 收藏 引用
            精品国产乱码久久久久久1区2区| 人妻无码αv中文字幕久久| 国产精品久久久久AV福利动漫| 伊人久久大香线蕉av不变影院 | 欧美久久久久久精选9999| 久久www免费人成看国产片| 亚洲欧洲久久av| 国产精品美女久久久| 亚洲国产精品嫩草影院久久| 国内精品九九久久久精品| 国内精品欧美久久精品| 色偷偷88888欧美精品久久久| 久久香蕉一级毛片| 久久99久久99精品免视看动漫| 国产一区二区精品久久| 四虎国产精品成人免费久久| 国产精品岛国久久久久| 亚洲欧美一区二区三区久久| 久久久久四虎国产精品| 亚洲中文精品久久久久久不卡| 久久久精品波多野结衣| 久久被窝电影亚洲爽爽爽| 国内精品综合久久久40p| 国产亚洲成人久久| 久久精品一区二区三区不卡| 久久SE精品一区二区| 中文字幕无码av激情不卡久久| 久久精品国产半推半就| 国产婷婷成人久久Av免费高清| 色欲综合久久躁天天躁| 久久er国产精品免费观看8| 国产精品九九九久久九九| 久久国产精品77777| 久久国产色av免费看| 久久夜色精品国产亚洲| 亚洲国产精品一区二区三区久久| 日韩精品国产自在久久现线拍 | 色综合久久综合网观看| 国产精品久久成人影院| 青青青青久久精品国产 | 久久久久无码精品国产不卡|