Is there any way to pass a class as a function pointer.
for example:
int compare(int a, int b)
{
return a - b;
}
void sort(int *ar, int (*pf)(int, int))
{
//a sorting algorithm.
}
class MyClass
{
bool condition;
public:
int compare(int a, int b)
{
if (condition)
return a - b;
else
return b - a;
}
};
void main()
{
int testAr[] = {0, 1, 2, 3};
sort(testAr, compare);
//MyClass m;
//sort(testAr, m.compare);
return 0;
}
I don't want to use static function instead of member function.