逸逸记事
逸逸记事

我的分类(专题)

首页(175)
儿子(9)
SIP技术(9)
Web2.0(12)
摄影和DVD(8)
软件开发随笔(18)
名古屋打工生活(11)
微软技术开发(47)
Java技术(12)
加拿大移民生活(20)
生活点滴(6)
第一份工作--上海贝尔(18)
完成项目(13)
回国后的生活(0)


最新日志
独行者
终于知道什么叫外包了
人生悲哀之事
水晶报表中显示动态图片
水晶报表中的简单参数设置
怀念下小黑
dotnet中的数据连接Timeout
老板的思路
又买房了
交通事故

最新回复
回复:独行者
回复:怀念下小黑
回复:老板的思路
回复:mjSip学习笔记
回复:老板的思路
回复:dotnet中的数据连接Timeo
回复:mjSip学习笔记
回复:交通事故
回复:交通事故
回复:又买房了

留言板

签写新留言

您好,很希望问您一个关于jain-sip
生活经历就是最大的财富,羡哦~
java的Web开发问题
回复:疑问
IT还不如妓女呢,呵呵
myjavaserver的空间
求助
您的子域名已开通

统计
blog名称:人在旅途
日志总数:175
评论数量:505
留言数量:13
访问次数:1679221
建立时间:2005年12月7日

链接

 

生命是过客,人在旅途。奶奶是信基督教的,没啥文化,却养育了四子二女,还带过九个孙辈。老人家对生命的看法就是“人都是客人,迟早要回去的。”就以《人在旅途》来纪念她。

 

«November 2025»
1
2345678
9101112131415
16171819202122
23242526272829
30

公告
  本人上传的源程序中可能引用或使用了第三方的库或程序,也可能是修改了第三方的例程甚至是源程序.所以本人上传的源程序禁止在以单纯学习为目的的任何以外场合使用,不然如果引起任何版权问题,本人不负任何责任.




     本站首页    管理页面    写新日志    退出
调整中...
[微软技术开发]How to use map of STL
人在旅途 发表于 2006/1/22 10:20:40

The function contain is the main function support by the STL, though MFC has many contain class like carray,clist.... But when you meet the event that you can't use MFC(like develop ATL project), you will like to use it and these C++ STL class are template. Now I will record some thoughts and experience about using map. Like following:   /////////////////////////////////////////////////////////////////////// #include "map"using namespace std ;   class CTask{public: int x; char pX[50]; CTask() ; ~CTask() ;    void operator = (CTask& task) {  x = task.x;  memcpy(pX,task.pX,50);    AfxMessageBox("="); };};   typedef map<int, CTask> INT2TASK; CTestxApp theApp;CTask::CTask() {  x = 0;} CTask::~CTask() {   }  INT2TASK theMap;     INT2TASK::iterator theIterator;   CTask task1 ; task1.x = 100; strcpy(task1.pX,"100"); theMap.insert(INT2TASK::value_type(0,task1));    task1.x = 1000;    CTask* task2; theIterator = theMap.find(0); task2 = &((*theIterator).second);  task2->x = 500; strcpy(task2->pX,"500");    theIterator = theMap.find(0); task2 = &((*theIterator).second);  theMap.clear(); Important: 1. The class you put to the map template, can't has any new or create function in the create function,because it will not be called in it's function "insert(...)", and the "insert(...)" will only use the memcpy(...) to duplicate a new object instance and save it in the map. So you can safely delete the resource object. 2. When you call the map function "clear()", it will delete all objects in the map, ofcourse it will voke the destructor function of the object. 3. When you want get a object from the map, there is two way:    a. CTask* task2;       theIterator = theMap.find(0);       task2 = &((*theIterator).second);   //what you get is the reference(point) of the object, so  you can change it and the result will be saved in the map.     b. CTask task2;       theIterator = theMap.find(0);       task2 = (*theIterator).second;   //what you get is a copy of the object(a new object), this time the function "operate =" of the CTask will be called(if has such function). So what you chang with the task2 will not affect the object in the map.

阅读全文(2200) | 回复(0) | 编辑 | 精华


发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)

站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.563 second(s), page refreshed 144794800 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号