I am trying to use callback function in my problem but I got into some troubles. In the sort() function, the parameter &compareType has an error:
Argument of type "bool (Person::*)(const Person& p1, const Person& p2)" is incompatible with parameter of type "compare"`
person.h
class Person
{
public:
bool compareType(const Person& p1, const Person& p2) { return ... };
void sort()
{
...
list->addInOrder(person, &compareType);
...
}
...
}
dlinkedlist.h
typedef bool (*compare)(const Person& p1, const Person&p2);
class dlinkedlist
{
public:
void addInOrder(const Person& person, compare comparefunc)
{
Person person2;
...
comparefunc(person, person2);
...
}
}
bool compareType(const Person& p1, const Person& p2)
is actually of type
bool (Person::*) (const Person&, const Person&)
You have to make your method static to have correct type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With