Functor as comparator in btAlignedObjectArray:quicksort

rraallvv
Posts: 30
Joined: Thu Feb 09, 2012 2:39 am

Functor as comparator in btAlignedObjectArray:quicksort

Post by rraallvv »

Why can't I use a functor as the comparator function in btAlignedObjectArray:quicksort?

Code: Select all

#include "btScalar.h"
#include "btAlignedAllocator.h"
#include "btAlignedObjectArray.h"

class Comparator
{
	btAlignedObjectArray<int> items;

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)
	{
		return a < 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;
}
I'm using Xcode 4.6, this code won't compile, the error is:

btAlignedObjectArray.h
Lines 345 and 347: No matching function for call to object of type 'const Comparator'
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Functor as comparator in btAlignedObjectArray:quicksort

Post by Flix »

rraallvv wrote:Lines 345 and 347: No matching function for call to object of type 'const Comparator'
int operator()(const int &a, const int &b) const ?
rraallvv
Posts: 30
Joined: Thu Feb 09, 2012 2:39 am

Re: Functor as comparator in btAlignedObjectArray:quicksort

Post by rraallvv »

Flix wrote: int operator()(const int &a, const int &b) const ?
Yes thanks, it was the missing const at the end