0

This is my code:

#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;
}

The error is No matching function for call to object of type 'const Comparator'

in lines 345 and 347 in btAlignedObjectArray.h

rraallvv
  • 2,875
  • 6
  • 30
  • 67

1 Answers1

1

Try to add const to your operator()

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

Also as you have captured by yourself already, myReference should be const as well

int myReference() const
//                ^^^^
billz
  • 44,644
  • 9
  • 83
  • 100
  • I kind of works, sorry I didn't include the whole story, I added the myReference() member function, that needs to be called from within the functor overloaded operator – rraallvv Aug 13 '13 at 06:07
  • The error is that myReference need to be constant, I guess I would have to refactor my code – rraallvv Aug 13 '13 at 06:08
  • basically, all non-static member functions don't intend to modify member should declare as const :) – billz Aug 13 '13 at 06:11