zoukankan      html  css  js  c++  java
  • functor

    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.

  • 相关阅读:
    命令[34]
    命令[33]
    命令[27]
    命令[38]
    命令[19]
    命令[22]
    命令[30]
    命令[37]
    命令[23]
    命令[26]
  • 原文地址:https://www.cnblogs.com/zhoug2020/p/4913694.html
Copyright © 2011-2022 走看看