Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-15-2009, 06:30 AM   PM User | #1
Shaitan00
New Coder

 
Join Date: Jan 2005
Posts: 74
Thanks: 0
Thanked 1 Time in 1 Post
Shaitan00 is an unknown quantity at this point
Question List.Sort(compare_function) - term does not evaluate to a function taking 2 arguments

I am trying to customize my sorting of a LIST using a compare_function, but for some odd reason it keeps giving me the following error:
error C2064: term does not evaluate to a function taking 2 arguments

Specifically, I have list created within class B which needs to be sorted, the list contains elements of type A* as shown below:

Class B code:
Code:
B::B()
{
list<A*> AList;

AList.push_back(new A(ID_1, CODE_1));
AList.push_back(new A(ID_2, CODE_2));

AtList.sort(&B::compareID);
}

bool B::compareID(A* first, A* second)
{
return true;	// test for now
}
Just for completness the following is the code for Class A:
Code:
Class A
{
	long ID;
	string sCode;
	A(_ID, _sCode) : ID(_ID), sCode(_sCode) {};
}
So, pretty much I just want to sort AList by ID, but for some odd reason this generates:
error C2064: term does not evaluate to a function taking 2 arguments

Also, in the future I am going to want to create a compareCode() function to also compare by code ... thought if one way works so will the other ...

Any clues, hints, or help would be greatly appreciated.
Thanks,
Shaitan00 is offline   Reply With Quote
Old 07-15-2009, 04:27 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
Off the top of my head, your compare function needs to be a static method.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 07-20-2009, 02:06 AM   PM User | #3
Dunna
Regular Coder

 
Join Date: May 2004
Location: New Hampshire, America
Posts: 245
Thanks: 0
Thanked 2 Times in 2 Posts
Dunna is an unknown quantity at this point
Can I see your sort function (if oracleguy wasn't right)? Also, is compareId a function, a variable, or both?
Dunna is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:43 PM.


Advertisement
Log in to turn off these ads.