hash_map的详解

时间:2015-03-02 04:05:15
【文件属性】:
文件名称:hash_map的详解
文件大小:36KB
文件格式:DOC
更新时间:2015-03-02 04:05:15
map hash_map stl 关于hash_map的用法与解释: #include #include #include using namespace std; //define the class class ClassA{ public: ClassA(int a):c_a(a){} int getvalue()const { return c_a;} void setvalue(int a){c_a=a;} private: int c_a; }; //1 define the hash function struct hash_A{ size_t operator()(const class ClassA & A)const{ // return hash(classA.getvalue()); return A.getvalue(); } }; //2 define the equal function struct equal_A{ bool operator()(const class ClassA & a1, const class ClassA & a2)const{ return a1.getvalue() == a2.getvalue(); } }; int main() { hash_map hmap; ClassA a1(12); hmap[a1]="I am 12"; ClassA a2(198877); hmap[a2]="I am 198877"; cout< 立即下载

网友评论