Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"__comp cannot be used as a function" c++ while trying next_permutation

Tags:

c++

I'm trying to do permutations with next_permutation from the stl, however I'm getting an error and I can't figure out how to fix it. I've tried googling, however the only results that come up are when people used the same function and function's variables name but thats not the case here.

Here's the error :

'__comp' cannot be used as a function

Here's the code :

struct rectangle{
    int n;
    int h;
    int w;
};

bool check(const rectangle& rect1,const rectangle& rect2){
    return rect1.n < rect2.n;
}

do{
//...
} while ( next_permutation(recs.begin(), recs.end(), check) ); // Getting error on this line.

Here's the full source code along with the sample input in case it's needed http://pastebin.com/eNRNCuTf

like image 235
Marijus Avatar asked Mar 21 '11 19:03

Marijus


1 Answers

H = rec4.w + max(rec1.h, rec2.h, rec3.h);

You don't want to pass rec3.h there - The error message simply say that the 3rd argument to max can't be used as a function. I believe you intended:

H = rec4.w + max(max(rec1.h, rec2.h), rec3.h);
like image 189
Erik Avatar answered Oct 23 '22 21:10

Erik