问问std::map

zhenzhubaoyou 2009-01-24 09:45:33
typedef std::map<String, Property*, String::FastLessCompare> PropertyRegistry;
PropertyRegistry d_properties;

这个map里一个键对应两个值么?在那个c++ primer里找了半天没找到是啥用法啊?一般都是看到的键值对,都是一对一的啊。请明白的兄台指教!
...全文
236 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yxjiang 2009-01-25
  • 打赏
  • 举报
回复
如果是三个的版本话,第三个参数为一个用于比较的函数对象。
waizqfor 2009-01-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lightnut 的回复:]
template <
class Key,
class Type,
class Traits = less <Key>,
class Allocator=allocator <pair <const Key, Type> >
>
class map



Parameters

Key
The key data type to be stored in the map.

Type
The element data type to be stored in the map.

Traits
The type that provides a function object that can compare two element values as sort keys to determine the…
[/Quote]
MSDN上有
LZ去看看吧
xiaoyisnail 2009-01-24
  • 打赏
  • 举报
回复
map有四个模板参数,后面两个有默认值,所以平时一般只用前两个指定key和value类型,第三个是比较函数,第四个是内存分配器,声明如下:

// TEMPLATE CLASS map
template<class _K, class _Ty, class _Pr = less<_K>,
class _A = allocator<_Ty> >
class map {
...
};
lightnut 2009-01-24
  • 打赏
  • 举报
回复
template <
class Key,
class Type,
class Traits = less<Key>,
class Allocator=allocator<pair <const Key, Type> >
>
class map



Parameters

Key
The key data type to be stored in the map.

Type
The element data type to be stored in the map.

Traits
The type that provides a function object that can compare two element values as sort keys to determine their relative order in the map. This argument is optional and the binary predicate less<Key> is the default value.

Allocator
The type that represents the stored allocator object that encapsulates details about the map's allocation and deallocation of memory. This argument is optional and the default value is allocator<pair <const Key, Type> >.

BenjaminHuang 2009-01-24
  • 打赏
  • 举报
回复
好像没有看到过 std::map 里单项能关联三个值的用法耶 map <String, Property*, String::FastLessCompare>
是不是搞错了?
wangyaosuper 2009-01-24
  • 打赏
  • 举报
回复
第一个参数是key的类型,第二个是对key进行散列的方法。
chin_chen 2009-01-24
  • 打赏
  • 举报
回复
是一对一的,后面的那个是插入时比较用的缺省函数,自己可以定义的。

64,670

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧