I thought it would be easy and convenient to define a small functor and perform a customized sort on some objects I have. However, I can‘t seem to get the functor to work. Here is some code that gives me a "no matching call" error:
class Cmp { bool operator()(int x, int y) const { return x < y; } }; vector<int> vec; std::sort(vec.begin(), vec.end(), Cmp() );
As far as I can tell I followed the requirements exactly, but apparently I didn‘t. Can anyone tell me what is wrong with the above code? Thanks for your time.
时间: 2024-10-07 21:21:04