如何存储CMap数据的CMap [英] how do is store CMap of CMap data

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

问题描述

hi,

i want to use the CMap of CMap for storing some data

e.g.

class A{
    CMap<CString, LPCSTR,B,B&> mapB;

    CString name;
};

class B{
    CString name;
};

and now i want use the
CMap<CString, LPCSTR,A,A&> mapA;
on compiling here it was giving the error like
"'operator =' function is unavailable"
so in class A i added operator
void operator=(const A& ao_obj){
//what should i write here
}

then it compiled with 0 errors
and then i added data in map A

CString key="1";
A aobj;
aobj.name="SomeName";
mapA[key] = aobj;

Now at the time of retrieving this A object
it is not storing the value in the object
means
CString k1="1";
A objA;
mapA.Lookup(k1,objA);

so here it should store the value in objA
but it is not doing this
it is happening because of operator=
what should i write in 'operator=' function?

推荐答案

我找到了解决方法,

在operator =函数中,

无效运算符=(const A& ao_obj ){

//在这里,我们应该从传递的'' ao_obj ''
中设置类A的成员 名称= ao_obj.name;
}

通过这样做,在查找时它存储了各个键的值.

无论如何都要感谢大家
i found the solution,

in operator= function,

void operator=(const A& ao_obj){

//here, we should set the members of the class A from the passed ''ao_obj''
name = ao_obj.name;
}

by doing this, on look up it is storing the value for the respective key.

anyways thanks to all of you


一切正常
您得到正确的答案.
its ok
u got the answer correct.


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

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