Page 1 of 1

## 2 Replies - 429 Views - Last Post: 08 February 2013 - 03:27 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=311629&amp;s=bb38500b57c0d10bd9e084365ccc04fe&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 krillov

• New D.I.C Head

Reputation: 1
• Posts: 36
• Joined: 18-November 12

Posted 08 February 2013 - 03:01 PM

Hey!

How to start .. I have a vector of objects. Iīd like to sort the vector by different things like name, etc. If I understood right, using sort algorithm like this only
```sort(persons.begin(), persons.end())
```
would basically use my overloaded " operator< ". My question is how can I tell the sort algorithm that it would sort the vector by name or by other part of the object? I found this site on the net: http://msdn.microsof...x(v=vs.80).aspx
As I see the parameters of the operator function are only the objects of the vector and itīs only written in the function by which part of object it should sort the vector. I could write more operator functions but how would the algorithm know which one to call? Itīs kind of hard for me to get familiar with the object oriented part so I appreciate any help. Thanks!

Is This A Good Question/Topic? 0

## Replies To: Question about vector sorting / operator overloading

### #2 jimblumberg

Reputation: 5465
• Posts: 17,015
• Joined: 25-December 09

Posted 08 February 2013 - 03:06 PM

There is another version of std::sort where you provide the sort comparison function you may want to investigate that version. Here is another example: std::sort

Jim

This post has been edited by jimblumberg: 08 February 2013 - 03:08 PM

### #3 krillov

• New D.I.C Head

Reputation: 1
• Posts: 36
• Joined: 18-November 12