-2

I am trying to use custom sort inside a class, such as sort(arr,arr+n,cust); inside a class function. Custom sort looks like this:

bool cust (int a, int b) {
  return pos[a]<pos[b];
}

Where pos is an array inside class. But it does not compile, and gives compilation error

"invalid use of non-static member function" how to get rid of compilation error.

my code -> https://pastebin.com/W1zw0A5s

I have tried writing:

static bool cust (int a, int b) {
     /* same code */
} 

which hasn't helped.

HolyBlackCat
  • 63,700
  • 7
  • 105
  • 170
Vikram
  • 584
  • 1
  • 4
  • 9

1 Answers1

0

According to the pastebin link, this function is a member function in your class. You need to bind the this pointer to it in order to use it:

sort(sa,sa+n, [this](int a, int b){ return this->sufCmp(a,b); } );
Shloim
  • 4,881
  • 19
  • 34