CMap或CMapPtrToPtr [英] CMap or CMapPtrToPtr

查看:97
本文介绍了CMap或CMapPtrToPtr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想将对象存储在CMap
我想将我的课程用作键和值.

比如说

Hi,
i want store the objects in CMap
and i want to use my class as a key and value.

say for e.g.

class A{
public:
   CString name;
}


现在我想使用A类作为CMap
中的键和值 所以为此,我正在使用CMapPtrToPtr.


and now i want to use class A as a key and value in CMap
so for this i am using CMapPtrToPtr.

CMapPtrToPtr map;

A* key1 = new A();
key1->name="1";
A* value1 = new A();
value1->name="ONE";
map.SetAt(key1,value1);

//upto this there is no problem but while traversing the map it is giving error
means 
        POSITION Position = map.GetStartPosition();
	while (Position!=NULL) {
	  A* lo_key = new TRY1();
	  A* lo_value = new TRY1();
	  map.GetNextAssoc(Position, key, value);//here i am getting error	    
	  
	}


错误是:


error is:

cannot convert parameter 2 from ''class A *'' to ''void *& ''


我如何获得关键和价值?
使用CMapPtrToPtrs是否正确?还是有其他方法可以做到?


How do i get the key and value?
is it right to use CMapPtrToPtrs? or is there any other way to do this?

推荐答案

尝试一下:):
Try it :) :
class A;

typedef CTypedPtrMap<CMapPtrToPtr, A*, A*> CYourMap;

void SomeIteration(CYourMap& map)
{
  POSITION pos(map.GetStartPosition());
  while (pos) {
    A* pAKey(NULL);   // NULL - since it does receive the answer from GetNextAssoc :)
    A* pAValue(NULL); // NULL - since it does receive the answer from GetNextAssoc :)
    map.GetNextAssoc(pos, pAKey, pAValue);
    
    if (pAKey && pAValue) {
      // use the answer here :)
    }
  }
}


这篇关于CMap或CMapPtrToPtr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆