• <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)德,非澹薄無以明志,非寧靜無以致遠。
            隨筆 - 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

            久久这里只有精品首页| 99热成人精品热久久669| 狠狠色伊人久久精品综合网| 精品免费tv久久久久久久| 久久精品人妻一区二区三区| 亚洲中文字幕伊人久久无码| 99久久无色码中文字幕| 日本国产精品久久| 午夜人妻久久久久久久久| 中文字幕一区二区三区久久网站 | 香蕉aa三级久久毛片| 久久午夜伦鲁片免费无码| 久久精品综合一区二区三区| 国内高清久久久久久| 狠狠精品久久久无码中文字幕| 伊人久久大香线蕉av不卡| 久久久久亚洲精品无码网址| 久久w5ww成w人免费| 国产精品久久久久久五月尺| 国内精品久久久久久久久电影网| 99久久久国产精品免费无卡顿 | 久久w5ww成w人免费| 99久久免费国产精品特黄| 久久综合九色综合欧美就去吻| www.久久热.com| 91精品国产91久久久久福利| 亚洲色欲久久久综合网东京热| 香港aa三级久久三级老师2021国产三级精品三级在 | 久久夜色精品国产亚洲| 国内精品伊人久久久久av一坑| A级毛片无码久久精品免费 | 久久久久久毛片免费看| 91精品国产91久久久久久青草| 国产精品一区二区久久精品| 波多野结衣中文字幕久久 | 久久国产亚洲精品无码| 亚洲国产美女精品久久久久∴| 精品熟女少妇AV免费久久| 久久精品国产色蜜蜜麻豆| 久久久这里有精品| 亚洲AV日韩AV天堂久久|