Почему я не могу использовать функтор в качестве функции сравнения в btAlignedObjectArray: quicksort?

Это мой код:

#include "btScalar.h"#include "btAlignedAllocator.h"#include "btAlignedObjectArray.h"
class Comparator
{
btAlignedObjectArray<int> items;

// Edit: this member function is to be called from within the comparator
int myReference()
{
return 0;
}

public:
Comparator()
{
items.push_back(5);
items.push_back(1);
items.push_back(3);
items.push_back(8);
}

int operator()(const int &a, const int &b) const
{
return a + myReference() < b;
}

void doSort()
{
items.quickSort(*this);

for (int i=0; i<items.size(); i++) {
printf("%d\n", items[i]);
}
}
};

int main()
{
Comparator myClass;

myClass.doSort();

printf("done!\n");

return 0;
}

Ошибка No matching function for call to object of type 'const Comparator'

в строках 345 и 347 в btAlignedObjectArray.h

0

Решение

Попробуй добавить const на ваш operator()

int operator()(const int &a, const int &b) const
//                                         ^^^^^
{
return a < b;
}

Кроме того, как вы уже захватили, myReference должен быть постоянным

int myReference() const
//                ^^^^
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector