List.Sort(compare_function) - term does not evaluate to a function taking 2 arguments

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2006
Posts: 35
Reputation: Shaitan00 has a little shameless behaviour in the past 
Solved Threads: 0
Shaitan00 Shaitan00 is offline Offline
Light Poster

List.Sort(compare_function) - term does not evaluate to a function taking 2 arguments

 
0
  #1
Jul 15th, 2009
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:
  1. B::B()
  2. {
  3. list<A*> AList;
  4.  
  5. AList.push_back(new A(ID_1, CODE_1));
  6. AList.push_back(new A(ID_2, CODE_2));
  7.  
  8. AtList.sort(&B::compareID);
  9. }
  10.  
  11. bool B::compareID(A* first, A* second)
  12. {
  13. return true; // test for now
  14. }

Just for completness the following is the code for Class A:
  1. Class A
  2. {
  3. long ID;
  4. string sCode;
  5. A(_ID, _sCode) : ID(_ID), sCode(_sCode) {};
  6. }

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,
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 440
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 68
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: List.Sort(compare_function) - term does not evaluate to a function taking 2 arguments

 
0
  #2
Jul 15th, 2009
Is this the exact code you compiled? And is that the only error you got? Your code has a lot of other compiler errors too as of now. It'll be good if you paste the entire code after you remove all the errors that you can and then we'll be able to help you better with the one's remaining.
thanks
-chandra
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,605
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 460
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: List.Sort(compare_function) - term does not evaluate to a function taking 2 arguments

 
0
  #3
Jul 15th, 2009
Shaitan00,
compareID method either static or friend.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: List.Sort(compare_function) - term does not evaluate to a function taking 2 arguments

 
0
  #4
Jul 15th, 2009
Why is compareId() a member of B

This does work:
  1. #include <string>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. struct A
  7. {
  8. long ID;
  9. string sCode;
  10. A(long ID_, string const & sCode_) : ID(ID_), sCode(sCode_) {}
  11. };
  12.  
  13. bool compareID(A* first, A* second)
  14. {
  15. return true; // test for now
  16. }
  17. class B
  18. {
  19. B()
  20. {
  21. list<A*> AList;
  22.  
  23. AList.push_back(new A(1, "one"));
  24. AList.push_back(new A(2, "two"));
  25.  
  26. AList.sort(compareID);
  27. }
  28.  
  29. };
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: List.Sort(compare_function) - term does not evaluate to a function taking 2 arguments

 
1
  #5
Jul 15th, 2009
Poster evaluates to a thread posted on two forums.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC