Callback function: Incompatible argument

Viewed 791

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);
        ...
    }
}
4 Answers
Related