如何将配对插入地图 [英] How to insert pair into map

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

问题描述

我具有以下地图结构: map<配对<int,int> ;, object *> ,我希望插入其中.

I have the following map structure: map < pair < int,int >, object* > and I wish to insert into it.

既然我要插入一对和一个对象,并且必须做成一对,该怎么办?

How would I do it since I am trying to insert a pair and an object and I must make a pair out of this?

我应该使用我拥有的货币对和对象中的 make_pair()创建一个新货币对吗?如果是这样,请您让我知道该怎么做?

Should I create a new pair using make_pair() out of the pair and object that I have? If so, could you please let me know how to do this?

推荐答案

object * myObject = // get an object somehow
myMap.insert(std::make_pair(std::make_pair(1,2), myObject));

typedef map<pair<int, int>, object *> MapType;
object * myObject = // get an object somehow
myMap.insert(MapType::value_type(std::make_pair(1,2), myObject));

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

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