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

            Benjamin

            靜以修身,儉以養(yǎng)德,非澹薄無以明志,非寧靜無以致遠(yuǎn)。
            隨筆 - 397, 文章 - 0, 評論 - 196, 引用 - 0
            數(shù)據(jù)加載中……

            linux平臺hash_map使用示例

             1 #include <string
             2 #include <iostream> 
             3 #include <ext/hash_map>
             4 using namespace __gnu_cxx; 
             5  
             6 //define the class 
             7 class ClassA{ 
             8 public
             9     ClassA(int a):c_a(a){} 
            10     int getvalue()const { return c_a;} 
            11     void setvalue(int a){c_a;} 
            12 private
            13     int c_a; 
            14 }; 
            15 
            16 //1 define the hash function 
            17 struct hash_A
            18 { 
            19     size_t operator()(const class ClassA & A)const
            20     { 
            21         // return hash<int>(classA.getvalue()); 
            22         return A.getvalue(); 
            23     } 
            24 }; 
            25 
            26 
            27 //2 define the equal function 
            28 struct equal_A
            29 { 
            30     bool operator()(const class ClassA & a1, const class ClassA & a2)const
            31     { 
            32         return a1.getvalue() == a2.getvalue(); 
            33     } 
            34 };
            35 
            36 struct foo
            37 {
            38     int a ;
            39     int b ;
            40     foo(int x,int y):a(x),b(y) {};// ok, 先初始化i,后初始化j
            41     foo(){};
            42 };
            43 int main() 
            44 { 
            45     hash_map<ClassA, foo, hash_A, equal_A> hmap; 
            46     
            47     ClassA a1(12); 
            48     foo t1(122,233);
            49     hmap[a1]=t1; 
            50 
            51     ClassA a2(198877);
            52     foo t2(198877,6698);
            53     hmap[a2]=t2; 
            54 
            55     std::cout<<hmap[a1].a<<std::endl; 
            56     std::cout<<hmap[a2].b<<std::endl; 
            57     
            58     hash_map<ClassA, foo, hash_A, equal_A>::iterator it = hmap.find(12);
            59     if(it != hmap.end())
            60     {
            61         std::cout<<it->second.a<<std::endl;
            62    }
            63 
            64         foo t3(43,67);
            65     hmap.insert(pair<int, foo>(78,t3));
            66     return 0; 
            67 } 
            68 
            如果鍵值是指針可這樣寫:hash_map<int,classA*>,key是int,classA*是value的類型,和vc中使用的情況一樣   

            posted on 2015-01-02 15:51 Benjamin 閱讀(882) 評論(0)  編輯 收藏 引用 所屬分類: linux

            麻豆精品久久久一区二区| 久久天天躁狠狠躁夜夜2020老熟妇| 国产精品欧美久久久久天天影视| 久久99精品久久久久久久不卡| 精品国产青草久久久久福利| 午夜福利91久久福利| 久久青草国产精品一区| 国产精品久久久久…| 精品一区二区久久| 青青热久久综合网伊人| 久久精品国产亚洲网站| 国产成人久久777777| 久久久久婷婷| 欧美精品乱码99久久蜜桃| 亚洲国产另类久久久精品小说| 伊人久久综合成人网| 久久精品国产亚洲精品2020| 国产一久久香蕉国产线看观看| 久久综合中文字幕| 亚洲欧美日韩精品久久亚洲区| 日韩精品久久无码人妻中文字幕 | 久久久综合香蕉尹人综合网| 日韩久久无码免费毛片软件| 亚洲人成网站999久久久综合| 少妇无套内谢久久久久| 91精品国产综合久久婷婷| 亚洲欧美日韩精品久久| 思思久久99热只有频精品66| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 看久久久久久a级毛片| 国产精品久久波多野结衣| 久久精品亚洲福利| 国内精品久久久久影院优| 无码任你躁久久久久久| a高清免费毛片久久| 一级女性全黄久久生活片免费| 久久久精品2019免费观看| 久久夜色撩人精品国产小说| 久久99精品久久久久久hb无码 | 99精品久久久久中文字幕| 久久国产香蕉视频|