No matching function for call to 'sort(std::vector<Interval>::iterator, std::vector<Interval>::it


  • 0
    R

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

    I compiled correctly in VS and gcc3.2.3, is it because gcc 4 do not support sort(iterator, iterator, sortcompare) function? or other problems, thank you!

    Here is code

    {
    bool SortComp(const Interval& T1, const Interval&T2)
    {
    	return T1.start<T2.start;
    }
    ...
    sort(intervals.begin(),intervals.end(),SortComp);
    }

  • 0
    R

    I also compiled corretly in gcc 4.4.7 : )


  • 1
    S

    Not sure if the code should be

    class {
    static bool SortComp(const Interval& T1, const Interval&T2)
    {
        return T1.start<T2.start;
    }
    
    {
    
    ...
    sort(intervals.begin(),intervals.end(), SortComp);
    }
    }
    

    And please check our environment here.


  • 0
    R

    OK, thanks for your help, it works : )
    but why should be static bool


  • 0
    Y

    I guess you defined SortComp() as a member function in Class Solution. You cannot call a non-static member function without creating an object of that class. That is why this error occurs. But I don't have a cue why you can get your previous code successfully compiled.


  • 0
    R

    but I can call other member function, maybe the OJ will create a instance of solution class, but I am not sure. Do you mean a function as a parameter is not allowed? For previous compiling, it;s my all fault, as I do not write class, just some functions, sorry for my not clearity for this quesiton: )


  • 0
    Y

    OJ will definitely create a instance of class Solution. But you should call non-static function member function as instance_name.function_name(). You can also try moving SortComp() outside of class Solution (and it will be a global function, just like your previous code).


  • 0
    R

    OK, I know your meaning, thanks : )


Log in to reply
 

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