【问题标题】:Insert into map with pair as key and list as value [closed]以对作为键并将列表作为值插入到地图中[关闭]
【发布时间】:2017-08-19 15:18:23
【问题描述】:

我在 C++ 中有以下地图:

typedef std::pair<int, int> iPair;

std::map< iPair, std::list< iPair > > world;

我想为一对(u,v)插入和更新地图 -> 推回列表:

 iPair src = make_pair(p1, u1);
 iPair dst = make_pair(p2, u2);
 map[src].push_back(dst);

尝试访问 map[src] 时出现编译错误:

错误:在“[”标记之前缺少模板参数

【问题讨论】:

  • 不是map[src],而是world[src]——这是你的变量名,不是吗?
  • 您有可能拥有using namespace std;,这导致您对map 的使用被解析为std::map,这需要一个模板参数,如错误所述。

标签: c++ dictionary std-pair


【解决方案1】:

您需要world[src],因为这是您的地图变量的名称,应该可以使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-30
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 2022-08-02
    • 2016-09-09
    相关资源
    最近更新 更多