Click here to Skip to main content
15,919,613 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: OnIdle Pin
Anonymous27-Jan-04 2:12
Anonymous27-Jan-04 2:12 
GeneralRe: OnIdle Pin
Michael Dunn27-Jan-04 7:07
sitebuilderMichael Dunn27-Jan-04 7:07 
GeneralSorting 'std::list' -s filled with class-pointers leads to a compile error Pin
clayman8726-Jan-04 8:49
clayman8726-Jan-04 8:49 
GeneralRe: Sorting 'std::list' -s filled with class-pointers leads to a compile error Pin
Joaquín M López Muñoz26-Jan-04 10:22
Joaquín M López Muñoz26-Jan-04 10:22 
GeneralRe: Sorting 'std::list' -s filled with class-pointers leads to a compile error Pin
clayman8726-Jan-04 23:34
clayman8726-Jan-04 23:34 
GeneralRe: Sorting 'std::list' -s filled with class-pointers leads to a compile error Pin
clayman8727-Jan-04 0:15
clayman8727-Jan-04 0:15 
GeneralRe: Sorting 'std::list' -s filled with class-pointers leads to a compile error Pin
pi31415638-Mar-04 10:56
pi31415638-Mar-04 10:56 
GeneralRe: Sorting 'std::list' -s filled with class-pointers leads to a compile error Pin
clayman879-Mar-04 1:36
clayman879-Mar-04 1:36 
Yes, of course.

The solution is quite simple, almost trivial, but only if you think "with a microsofter's head".

So the secret is that you, instead of deriving your sorter class from the std::greater<...>, have to derive the std::greater<cyourclass> from your CYourSorterClass, which actually doesn't exists.

to be clear:

so just extend std with the following lines:

<br />
namespace std<br />
{<br />
	template<> struct greater<CYourClass*> : public binary_function<CYourClass*, CYourClass*, bool><br />
	{<br />
		bool operator()(const CYourClass*& x, const CYourClass*& y) const<br />
		{<br />
			// if you don't have the class' operator< overloaded<br />
			return x->sortbyvalue < y->sortbyvalue;<br />
			// if you do have<br />
			return x < y;<br />
		}<br />
	};<br />
}<br />


then sort your list just the same way as it was a 'int' etc...:

<br />
nodes.sort( std::greater<CYourClass*> ( ) );<br />


that's it. I hope I could help.
GeneralRe: Sorting 'std::list' -s filled with class-pointers leads to a compile error Pin
pi31415639-Mar-04 9:45
pi31415639-Mar-04 9:45 
GeneralSharing common classes across projects Pin
James Bryan Johnson26-Jan-04 8:46
James Bryan Johnson26-Jan-04 8:46 
GeneralRe: Sharing common classes across projects Pin
Carlos Antollini26-Jan-04 8:52
Carlos Antollini26-Jan-04 8:52 
GeneralRe: Sharing common classes across projects Pin
Ed K26-Jan-04 12:25
Ed K26-Jan-04 12:25 
GeneralStarting programs when windows logs Pin
toxcct26-Jan-04 8:11
toxcct26-Jan-04 8:11 
GeneralRe: Starting programs when windows logs Pin
David Crow26-Jan-04 8:30
David Crow26-Jan-04 8:30 
GeneralRe: Starting programs when windows logs Pin
toxcct26-Jan-04 8:53
toxcct26-Jan-04 8:53 
GeneralRe: Starting programs when windows logs Pin
l a u r e n26-Jan-04 9:39
l a u r e n26-Jan-04 9:39 
GeneralRe: Starting programs when windows logs Pin
David Crow26-Jan-04 10:52
David Crow26-Jan-04 10:52 
GeneralRefreshing windows systray Pin
haritadala26-Jan-04 7:58
haritadala26-Jan-04 7:58 
GeneralRe: Refreshing windows systray Pin
SJolly27-Jan-04 0:26
SJolly27-Jan-04 0:26 
GeneralRe: Refreshing windows systray Pin
haritadala27-Jan-04 3:56
haritadala27-Jan-04 3:56 
GeneralC++ operator question Pin
Ed K26-Jan-04 7:55
Ed K26-Jan-04 7:55 
GeneralRe: C++ operator question Pin
toxcct26-Jan-04 8:30
toxcct26-Jan-04 8:30 
GeneralRe: C++ operator question Pin
J. Eric Vaughan26-Jan-04 8:44
J. Eric Vaughan26-Jan-04 8:44 
GeneralRe: C++ operator question Pin
Jörgen Sigvardsson26-Jan-04 9:02
Jörgen Sigvardsson26-Jan-04 9:02 
GeneralRe: C++ operator question Pin
J. Eric Vaughan26-Jan-04 9:35
J. Eric Vaughan26-Jan-04 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.