map<string ,int,less<string> > STR2INT; 怎样理解这条语句?
答案:1 悬赏:0 手机版
解决时间 2021-11-11 11:17
- 提问者网友:藍了天白赴美
- 2021-11-10 19:13
map<string ,int,less<string> > STR2INT; 怎样理解这条语句?
最佳答案
- 五星知识达人网友:思契十里
- 2021-11-10 19:21
map为一个模板,STL 中的 有序容器,其定义为
template < class Key, // map::key_type
class T, // map::mapped_type
class Compare = less, // map::key_compare
class Alloc = allocator > // map::allocator_type
> class map;
也就是说,代码用 string,int和less 三个参数(第四个被缺省了)实例化模板map,并定义了该模板实例的对象STR2INT。
less也是一个模板,less 是less模板的一个实例。
BTW,我猜想 这段代码之前 还应该有个 typedef追问是的,省略了typedef,less是个类模板,它有什么功能呢?追答template struct less : binary_function {
bool operator() (constT& x,constT& y) const {
returnx }
};
template < class Key, // map::key_type
class T, // map::mapped_type
class Compare = less
class Alloc = allocator
> class map;
也就是说,代码用 string,int和less
less也是一个模板,less
BTW,我猜想 这段代码之前 还应该有个 typedef追问是的,省略了typedef,less是个类模板,它有什么功能呢?追答template
bool operator() (constT& x,constT& y) const {
returnx
};
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯