地图错误 [英] Error In Map

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

问题描述

你好

我在以下代码中遇到问题:

Hello

I have problem in following code:

struct node
{
    CString         Name;
    CString         Add;
    CStringArray    Str;
}

std::map<char*>link; 



在上面我声明了一个结构&地图.
然后我将元素添加到map中,如下所示:



Above I declare a structure & map.
Then I add the element in map as follows:

struct node NODE;
CString lv_str;
GetDlgItemText(IDC_EDIT1,lv_str);
NODE.Name = lv_str;
GetDlgItemText(IDC_EDIT2,lv_str);
NODE.Add= lv_str;
NODE.Str.SetAt(0,lv_str);
link.insert(map<char*,node>::value_type("vaibhav",NODE));



它将给出如下错误:

错误C2679:二进制"=":未定义运算符,该运算符采用类型为"struct std :: pair< char node =">的右侧操作数(或没有可接受的转换)


如果有任何语法错误,请忽略它&另外,如果您有其他想法要在地图上插入该物品,请告诉我.

还有一件事是,如果我从结构中删除str元素,则此代码将正常工作.



It will give error as follows:

error C2679: binary ''='' : no operator defined which takes a right-hand operand of type ''struct std::pair<char node="">''(or there is no acceptable conversion)


If this has any gramatical mistakes please ignore it & also if you have any other ideas to insert the item in the map please tell me.

One more thing is that if I remove str element from structure then this code works properly.

推荐答案

不幸的是,CStringArray没有复制构造函数.映射中的值类型必须是可复制构造的,以便...

CStringArray无法复制可构造
->节点不可复制可构造
-> std :: pair< char *,节点>不能复制可构造的
->错误2582!

解决此问题的一种快速方法是不要弄乱1991年的样式集合类,而开始使用std :: vector.这比使用MFC集合进行所有手动迭代要容易得多.

干杯,

Ash
Unfortunately CStringArray hasn''t got a copy constuctor. Value types in a map have to be copy constructable so...

CStringArray not copy constructable
-> node not copy constructable
-> std::pair< char *, node > not copy constructable
-> error 2582!

One quick way around this problem is not to mess about with 1991 style collection classes and start using std::vector instead. It''s a lot easier than all the manual iteration you have to do with MFC collections.

Cheers,

Ash


忽略所有小错误,这应该起作用:

首先,您需要在地图声明中指定键类型,如下所示:
std :: map< char *,node> link;

之后,您可能希望仅使用[]运算符插入项目:

节点NODE;
//此处的节点初始化
//...
//插入项目(如果地图条目尚不存在,则会创建该条目)
link ["vaibhav"] = NODE;

祝您好运,如果有帮助,请告诉我!
Ignoring all minor errors, this is what should work:

First of all you need to specify the keytype in the map declaration like so:
std::map<char*,node>link;

After that you may wish to insert items simply by using the [] operator:

node NODE;
//Node init here
//...
//Insert item (the map entry will be created if it was not there yet)
link["vaibhav"] = NODE;

Good luck to you and please let me know if this helps!


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

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