Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:39:24+00:00 2026-05-16T23:39:24+00:00

hey, i am trying to sort my set container using afunctor: struct CompareCatId :

  • 0

hey, i am trying to sort my set container using afunctor:

struct CompareCatId : public std::binary_function<Vehicale*, Vehicale*, bool>
{
    bool operator()(Vehicle* x, Vehicle* y) const
    {   
        if(x->GetVehicleType() > y->GetVehicleType())
            return true;
        else if (x->GetVehicleType() == y->GetVehicleType() 
                               && x>GetLicenseNumber() > y->GetLicenseNumber())
                return true;
            else
                return false;
}
};

and this is how i defined my Set :

      set<Vehicale*,CompareCatId>* m_vehicalesSet;

and ofc i did not forget to include algorithm

i tried using this line for sorting :

 sort(m_vehiclesSet->begin(),m_vehiclesSet->end()); 

for some reason i am getting this akward error :

 error C2784: 'reverse_iterator<_RanIt>::difference_type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::_Tree_const_iterator<_Mytree>'

thanks in advance for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:39:24+00:00Added an answer on May 16, 2026 at 11:39 pm

    A std::set is sorted automatically as you insert elements into it. You don’t need to (and you can’t) sort it manually.

    Just skip sort(begin, end); and everything will be just fine!

    Also, in this case your functor mimics operator<, so all you have to write is:

    struct CompareCatId : public std::binary_function<Vehicale*, Vehicale*, bool>
    {
        bool operator()(Vehicle* x, Vehicle* y) const
        {   
            return x->GetVehicleType() < y->GetVehicleType();
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I was trying to delete an item form a list (without using set
Hey folks I am trying to implement a search functionality in a website using
Hey all. Im trying to sort out how to get MATLAB running as best
Hey all, I'm trying to write a sort function but am having trouble figuring
Hey guys i'm trying to convert url which looks like this example.com/sometype/author-name/sort-date or example.com/sometype/author-name/sort-date/something-value/
Hey i'm trying to make my website delete a file using the unlink(); function.
Hey I am trying to just set up the basic structure for some basic
Hey I am trying to extract this link: https://aulib.abdn.ac.uk:443/F/PEYK3FS2A56KCUKNUE2DNC111QPYC4T1AIPEQ3VP7VXK27HHFM-41314?func=short-sort&set_number=010039 From this I have tried
Hey all trying to play with nodejs MVC using express and mongoose. I have
Hey I am trying to do the nested sorting using jQuery I am getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.