sort(mMyClassVector.begin(), mMyClassVector.end(),
[](const MyClass & a, const MyClass & b)
{
return a.mProperty > b.mProperty;
});
I'd like to use a lambda function to sort custom classes in place of binding an instance method. However, the code above yields the error:
error C2564: 'const char *' : a function-style conversion to a built-in type can only take one argument
It works fine with boost::bind(&MyApp::myMethod, this, _1, _2)
.
Can the problem be with the "a.mProperty > b.mProperty" line? I've gotten the following code to work:
The output is:
Got it.
I assumed it'd figure out that the > operator returned a bool (per documentation). But apparently it is not so.
To much code, you can use it like this:
Replace "vec" with your class and that's it.