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:

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:

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,

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.

Shaitan00,
compareID method either static or friend.

Member Avatar for jencas

Why is compareId() a member of B

This does work:

#include <string>
#include <list>

using namespace std;

struct A
{
  long ID;
  string sCode;
  A(long ID_, string const & sCode_) : ID(ID_), sCode(sCode_) {}
};

bool compareID(A* first, A* second)
{
  return true;	// test for now
}
class B
{
  B()
  {
  list<A*> AList;

  AList.push_back(new A(1, "one"));
  AList.push_back(new A(2, "two"));

  AList.sort(compareID);
 }

};

Poster evaluates to a thread posted on two forums.

commented: Great eyes! +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.