No matching function for call to 'sort(std::vector<Interval>::iterator,..., <unresolved overloaded function type>)


  • 0
    C

    Dear all,
    As the title mentioned, when I upload my code, the problem always shows up, but it runs well in my machine, with vs 2008.
    Would you please tell me why it happens?

    class Solution {
    public:
        bool compareInterval( const Interval& first, const Interval& second ) {
    	    return first.start < second.start;
        }
        vector<Interval> merge(vector<Interval> &intervals) {
            int size = intervals.size();
    	    if( size < 2 )
    		    return intervals;
    	    sort( intervals.begin(), intervals.end(), compareInterval );
            int fStart = intervals[0].start;
            int fEnd = intervals[0].end;
            vector< Interval > newintervals;
            for( int i = 1; i< size; ++i ) {
               int curStart = intervals[i].start;
               int curEnd = intervals[i].end;
               if( fEnd >= curStart && fEnd <= curEnd ) {
                    fEnd = curEnd;              
               } else if ( fEnd < curStart) {
                   newintervals.push_back( Interval(fStart, fEnd ));
                   fEnd = curEnd;
                   fStart = curStart;
               }
            }
            newintervals.push_back( Interval(fStart, fEnd ));
            return newintervals;
        }
    };
    

    }


  • 0
    R

    haha, the same question I asked before, this is a function of a class, it will create a instance to call it, so for when the parameter is a function, it need to call a static member function of a class, I guess you do not use class to test in your local machine.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.