1
class Solution {
public:
    bool cmp(pair<int, int>& aa,pair<int, int>& bb){
        if(aa.first<bb.first) return true;
        else if(aa.second<bb.second) return true;
        else return false;
    }
    int maxEnvelopes(vector<pair<int, int> >& envelopes) {
        int i,sz;
        sz=envelopes.size();
        vector<int> v1,v2;
        vector<int>::iterator it1;
        vector<int>::iterator it2;
        sort(envelopes.begin(),envelopes.end(),cmp);
        for(i=0;i<sz;i++){
            it1=lower_bound(v1.begin(),v1.end(),envelopes[i].first);
            it2=lower_bound(v2.begin(),v2.end(),envelopes[i].second);
            if(it1==v1.end()&&it2==v2.end()){
                v1.push_back(envelopes[i].first);
                v2.push_back(envelopes[i].second);
            }
            else{
                v1[it1-v1.end()]=envelopes[i].first;
                v2[it2-v2.end()]=envelopes[i].second;
            }
            //cout<<v1.size()<<" "<<v2.size()<<endl;
        }
        return v1.size();
    }
};

I am getting "error: must use '.*' or '->*' to call pointer-to-member function" And it redirects me to predefined_ops.h file when I compile code in codeblocks compiler.

3
  • 2
    First of all, where do you get the error? Please mark it out with a comment or something like that. Secondly, does the cmp function really need to be a member function? And why isn't it a static member function? Commented Aug 26, 2016 at 4:36
  • Thanks a lot :) . After using static member function it is working now. Commented Aug 26, 2016 at 4:50
  • Whole page of useful information on pointers to member functions. Also look at std::function and std::bind Commented Aug 26, 2016 at 4:57

1 Answer 1

3

You cannot use a non-static member function, such as cmp, as an argument to sort.

The argument to sort has to be a global function, a static member function, or a callable object.

Make cmp a static member function for your program to work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.