C ++如何在std :: multimap中插入?

时间:2016-05-25 11:03:08

标签: c++ dictionary multimap

如何插入std::multimap <bool life, int id, std::pair < x, y >>

我将它用于存储数据的播放器和ia,它是最好的容器吗?

1 个答案:

答案 0 :(得分:3)

一点都不好。

多图的签名如下:

template < class Key,                                   // multimap::key_type
           class T,                                     // multimap::mapped_type
           class Compare = less<Key>,                   // multimap::key_compare
           class Alloc = allocator<pair<const Key,T> >  // multimap::allocator_type
           > class multimap;

使用多地图是错误的。

bool,这意味着您只使用两个节点01(或false´ and true`)。因此每个插入的元素都在其中一个中,因此您实际上是使用相同的键来登记元素。这是低效的。

int。好吧,好吧,不过我想知道您为什么要将bool映射到int

最后,签名中的错误:pair不是比较函数,但第三个模板参数必须是比较函数。如果您将其留空,则默认为less<bool>(因为您选择bool作为)。