473,699 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multipmap of pointers, sort by key

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

ex:

std::multimap<B OMBImntRT*, BOMBPortfolio*u ndPortMap;

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~

Apr 10 '07
12 3351
On 11 Apr 2007 07:58:09 -0700, "karen.b.lin@.. .com" wrote:
>But still don't get why overloading () ?
It's just a requirement of the STL. Alternatively the function might
have been called 'compare' or something like that. The advantage of
the STL solution is that you can use as predicate a free function and
an object with operator() alike.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Apr 11 '07 #11
Thank u all for the replies. Just want to further perfect my codes,
if i want to sort first by the key, then by value. How will i specify
it in my sorter, something like this? not sure where do i put the
value type in the sorter?

key: BOMBImntRT*
value: BOMBPortfolio*

struct UnderlyingsPtrS orter
{
bool operator() (const BOMBImntRT* a, const BOMBImntRT* b) const{
if(a->ImntName == b->ImntName)
//??
else
return a->ImntName < b->ImntName;
}
};

Apr 13 '07 #12
On Apr 13, 9:03 am, "karen.b....@gm ail.com" <karen.b....@gm ail.com>
wrote:
Thank u all for the replies. Just want to further perfect my codes,
if i want to sort first by the key, then by value. How will i specify
it in my sorter, something like this? not sure where do i put the
value type in the sorter?
You don't. Only the key will be passed to the predicate. If you want
the
value to be considered you should use std::set<Tand have the key
part
of the type you specify for T.

Apr 13 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6326
by: Tim Partridge | last post by:
How do I define the use of list::sort() when the list holds pointers? For example, #include <list> class foo { public: foo(int i): i(i) {}; ~foo();
14
3525
by: Roland Bengtsson | last post by:
I have a class Conception and I have this in a vector, it should be: vector<Conception> vek; // vector vector<Conception>::iterator vek; // iterator to vek But what if I want to have pointers to class Conception instead? How can I do that? And how should I write to declare an iterator to this vector?
6
9997
by: Der Andere | last post by:
I have an array of pointers (to a class) which I want to have sorted. I have implemented the < operator for the class but I guess STL sort will sort the pointers according to _their_ values (the addresses). Or will it work as I intended? Do you know ways to circumvent the problem? Thanks, Matthias -- Für emails Anweisung in der Adresse befolgen
6
3120
by: Matthias | last post by:
Hi, say I have a vector v1: std::vector<SomeType> v1; and I need a vector v2 of pointers to v1's elements: std::vector<SomeType*> v2;
18
3050
by: Matthias Kaeppler | last post by:
Hi, in my program, I have to sort containers of objects which can be 2000 items big in some cases. Since STL containers are based around copying and since I need to sort these containers quite frequently, I thought it'd be a better idea to manage additional containers which are initialized with pointers to the objects in the primary containers and sort those (only pointers have to be copied around then). However, that also means if I...
9
1672
by: Timothee Groleau | last post by:
Hi all, My name is Tim, I'm just getting started with C++ and this is my first post to the group. Is there a standard recommended approach to use a vector of pointers along with <algorithm>? To be specific, here is my situation, I have 2 classes A and B. Class A contains a private vector of pointers to B objects and I need to sort this
23
7402
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
22
3170
by: sandy | last post by:
I am trying to make a simulated directory structure application for a course. I am using a Vector to store pointers to my Directory objects (as subdirectories of the current object). In my header it looks like this (private section) vector<Directory*Directories;
11
656
by: Jeff Schwab | last post by:
Would std::sort ever compare an object with itself? I'm not talking about two distinct, equal-valued objects, but rather this == &that. The container being sorted is a std::vector. I've never seen this, but a coworker says he is. NB: I can't post sample code that reproduces the issue, nor do I claim any bug in the STL implementation (GCC 3.4.2). I'm just hoping a definitive answer resides in one of the brains who frequent this group.
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9034
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8883
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7750
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.