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

            靜以修身,儉以養德,非澹薄無以明志,非寧靜無以致遠。
            隨筆 - 397, 文章 - 0, 評論 - 196, 引用 - 0
            數據加載中……

            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 閱讀(879) 評論(0)  編輯 收藏 引用 所屬分類: linux

            久久久精品2019免费观看| 久久久久久久久66精品片| 99精品国产99久久久久久97| 女人香蕉久久**毛片精品| 久久99国产精品成人欧美| 久久久久久久久久久久久久| 新狼窝色AV性久久久久久| 97久久精品无码一区二区天美| 久久久久综合网久久| 欧美日韩精品久久久免费观看| 精品精品国产自在久久高清| 久久精品无码一区二区三区免费| 囯产极品美女高潮无套久久久 | 亚洲欧洲久久av| 精品国产VA久久久久久久冰| 精品久久久久久无码人妻蜜桃| 亚洲中文久久精品无码ww16| 品成人欧美大片久久国产欧美...| 中文字幕精品久久| 94久久国产乱子伦精品免费 | 一本大道久久a久久精品综合| 久久久久亚洲AV无码观看| 国内精品伊人久久久久影院对白| 日韩人妻无码精品久久久不卡| 人人狠狠综合88综合久久| 91精品婷婷国产综合久久| 国内精品久久久久影院一蜜桃| 国产69精品久久久久9999APGF| 久久无码AV中文出轨人妻| 99久久夜色精品国产网站| 久久久久亚洲AV成人片| 影音先锋女人AV鲁色资源网久久| 久久噜噜久久久精品66| 成人亚洲欧美久久久久| 国产精品久久久久久久久| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 欧美国产成人久久精品| 99久久www免费人成精品| 亚洲乱亚洲乱淫久久| 秋霞久久国产精品电影院| 欧美久久综合性欧美|