943,608 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 960
  • C++ RSS
Jul 15th, 2009
0

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

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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,
Reputation Points: 9
Solved Threads: 0
Light Poster
Shaitan00 is offline Offline
38 posts
since Jul 2006
Jul 15th, 2009
0

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

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.
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007
Jul 15th, 2009
0

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

Shaitan00,
compareID method either static or friend.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 15th, 2009
0

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

Why is compareId() a member of B

This does work:
C++ Syntax (Toggle Plain Text)
  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. };
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
Jul 15th, 2009
1

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

Poster evaluates to a thread posted on two forums.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to get local disk used space
Next Thread in C++ Forum Timeline: please help to convert from c to c++ just??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC