指针的多重映射,按键排序 [英] Multipmap of pointers, sort by key

查看:99
本文介绍了指针的多重映射,按键排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个指针多图。按键排序顺序似乎

搞砸了。


ex:


std :: multimap< BOMBImntRT * ,BOMBPortfolio * undPortMap;


我没有尝试创建对象的多图,b / c一些类

没有复制构造函数,它'创建一个会非常混乱。


无论如何都要将指针多图分类排序吗?


这个新的...欣赏你的帮助〜

I''ve created a multimap of pointers. The sort order by key seems
messed up.

ex:

std::multimap<BOMBImntRT*, BOMBPortfolio*undPortMap;

I did not try to create multimap of objects instead, b/c some classes
do not have copy constructors, and it''ll be very messy to create one.

Is there anyway to have the pointer multimap sorted?

New at this ... appreciate your help~

推荐答案

ka ********* @ gmail.com skrev:
ka*********@gmail.com skrev:

我已经创建了一个指针多图。按键排序顺序似乎是搞砸了。
I''ve created a multimap of pointers. The sort order by key seems
messed up.



怎么样?

How so?


4月10日下午1:22,令人讨厌的用户< O ... @ 127.0.0.1wrote:
On Apr 10, 1:22 pm, Obnoxious User <O...@127.0.0.1wrote:

karen.b ... 。@ gmail.com skrev:
karen.b....@gmail.com skrev:

我已经创建了一个指针多图。按键排序顺序似乎搞砸了b / b
搞砸了。
I''ve created a multimap of pointers. The sort order by key seems
messed up.



怎么样?


How so?



关键是工具,运营商<这是一个地图的例子:

$ b AMD P1

MOTOROLA P1

PACIFIC ETHANOL P1

MERRILL LYNCH P2

MOTOROLA P2

即使是第2行和第5行,两个键都是motorola,当我打印出来时,它们没有按照仪器排序。

订单似乎是插入订单。

the key is an instrument, operator < is on the name of the instrument.

Here''s an example of the map:

Instrument Portfolio
AMD P1
MOTOROLA P1
PACIFIC ETHANOL P1
MERRILL LYNCH P2
MOTOROLA P2
Even tho and line 2 and line 5, both keys are motorola, when i print
them out, it''s not sorted by the Instrument.
The order seems to be the insert order.


ka ********* @ gmail.com skrev:
ka*********@gmail.com skrev:

4月10日下午1:22,Obnoxious User< O ... @ 127.0.0.1wrote:
On Apr 10, 1:22 pm, Obnoxious User <O...@127.0.0.1wrote:

> karen.b .... @ gmail.com skrev:
>karen.b....@gmail.com skrev:

>>我已经创建了一个指针多图。按键排序顺序似乎搞砸了。
>>I''ve created a multimap of pointers. The sort order by key seems
messed up.


怎么样?

How so?



关键是一个工具,运营商<这是一个地图的例子:

$ b AMD P1

MOTOROLA P1

PACIFIC ETHANOL P1

MERRILL LYNCH P2

MOTOROLA P2


即使是第2行和第5行,这两个键都是motorola,当我打印出来时,它们没有按照仪器排序。

订单似乎是插入订单。


the key is an instrument, operator < is on the name of the instrument.

Here''s an example of the map:

Instrument Portfolio
AMD P1
MOTOROLA P1
PACIFIC ETHANOL P1
MERRILL LYNCH P2
MOTOROLA P2
Even tho and line 2 and line 5, both keys are motorola, when i print
them out, it''s not sorted by the Instrument.
The order seems to be the insert order.



使用指针作为键,默认情况下将使用指针地址排序。

添加自己的排序函数以按照您想要的方式对其进行排序。


struct my_sort {

bool operator()(BOMBImntRT * a,BOMBImntRT * b){

返回a-> ; some_value< b-> some_value;

}

};


std :: multimap< BOMBImntRT *,BOMBPortfolio *,my_sortundPortMap;

With pointers as keys, it will by default sort using pointer addresses.
Add your own sorting functor to sort it the way you want.

struct my_sort {
bool operator()(BOMBImntRT * a, BOMBImntRT * b) {
return a->some_value < b->some_value;
}
};

std::multimap<BOMBImntRT*, BOMBPortfolio*, my_sortundPortMap;


这篇关于指针的多重映射,按键排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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