CHAPTER4-18.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件夹名称:CHAPTER4-18.cpp
- #include<afx.h>
- #include<afxcoll.h>
- #include<iostream.h>
- class A:public CObject
- {
- WORD age;
- public:
- A(WORD x):age(x){}
- WORD operator!(){return age;}
- };
- void main()
- {
- WORD l=0,k;
- A *p;
- CMapWordToOb map;
- for(int i=0;i<5;i++)
- {
- while(l==0)cin>>l;
- if(i==3)k=l;
- p=new A(l);
- map.SetAt(!*p,(A*)p);//如果键值相同,则以新换旧
- l=0;
- }
- cout<<"The total number is "<<map.GetCount()<<endl;
- if(map.Lookup(k,(CObject*&)p))cout<<!*p;//如果返回值不为零则p将得到该对象的地址
- cout<<flush;
- cin.get();
- map.RemoveAll();
- }