Page 1 of 1

## 2 Replies - 276 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=e145660b8600edd88d0ccba8554ee3d9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 krillov

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

### #2 jimblumberg

Reputation: 4631
• Posts: 14,541
• 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

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