Click here to Skip to main content
15,918,808 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Help with IE plugin... Pin
Michael Dunn26-Jan-04 16:33
sitebuilderMichael Dunn26-Jan-04 16:33 
GeneralOnIdle Pin
lpRomang26-Jan-04 9:57
lpRomang26-Jan-04 9:57 
GeneralRe: OnIdle Pin
Michael Dunn26-Jan-04 16:38
sitebuilderMichael Dunn26-Jan-04 16:38 
GeneralRe: OnIdle Pin
Anonymous26-Jan-04 19:18
Anonymous26-Jan-04 19:18 
GeneralRe: OnIdle Pin
Michael Dunn26-Jan-04 19:44
sitebuilderMichael Dunn26-Jan-04 19:44 
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 
Hi!

I've been using MSVC++ 6.0 for about 5 years now, and by now, I haven't got any serious problems.
But today, I'd have liked to create a simple std::list with class-pointers in it. By that point everything were fine. But when I wanted to sort the list by a custom sorter, everything went wrong. I could not mangeged to sort the list, I always got the same compile error:

d:\projects\dc\try\try.cpp(42) : error C2664: 'void __thiscall std::list<class CTest *,class std::allocatorclass CTest *> >::sort(struct std::greater<class CTest *>)' : cannot convert parameter 1 from 'class CTestSorter' to 'struct std::greater<cla
ss CTest *>'
No constructor could take the source type, or constructor overload resolution was ambiguous


Please tell me, how could I sort such kind of lists in Visual C++ 6.0.
Thx in forward.

The code I tried to compile is here:

#include <iostream><br />
#include <list><br />
#include <math.h><br />
<br />
using namespace std;<br />
<br />
class CTest<br />
{<br />
friend class CTestSorter;<br />
protected:<br />
	int sortby;<br />
	int other;<br />
<br />
public:<br />
	CTest() : sortby(0), other(0) { };<br />
	CTest(int first, int second) : sortby(first), other(second) { };<br />
	void Write()<br />
	{<br />
		cout << sortby << ". - " << other << "\n";<br />
	}	<br />
};<br />
<br />
class CTestSorter<br />
{<br />
public:<br />
	bool operator() ( CTest* first, CTest*second )<br />
	{<br />
		return first->sortby < second->sortby;<br />
	}<br />
};<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
	list<CTest*> mylist;<br />
	int i;<br />
	cout << "Hello!\n";<br />
	for( i=0;i<10;i++ )<br />
	{<br />
		CTest* obj=new CTest( 10-i, rand() );<br />
		mylist.push_back( obj );<br />
	}<br />
	mylist.sort( CTestSorter() );<br />
	for( list<CTest*>::iterator it=mylist.begin();it!=mylist.end();it++ )<br />
	{<br />
		(*it)->Write();<br />
	}<br />
	return 0;<br />
}

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 
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 

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.