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 7657785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:06:20+00:00 2026-05-31T13:06:20+00:00

I’m having an issue porting my functor from windows to linux. (a functor to

  • 0

I’m having an issue porting my functor from windows to linux. (a functor to pass to stl::map for strict-weak ordering)
The original is as follows:

struct stringCompare{ // Utilized as a functor for stl::map parameter for strings 
    bool operator() (string lhs, string rhs){ // Returns true if lhs < rhs
        if(_stricmp(lhs.c_str(), rhs.c_str())  < 0) return true;
        else return false;
    }
};

As linux doesnt support _stricmp but uses strcasecmp instead, I changed it to:

struct stringCompare{ 
    bool operator() (string lhs, string rhs){ // Returns true if lhs < rhs
        if(strcasecmp(lhs.c_str(), rhs.c_str())  < 0) return true;
        else return false;
    }
};

And it is now complaining about “const” parameters:

passing const stringCompare as this argument of bool stringCompare::operator()  
(std::string, std::string)â discards qualifiers

I’m not entirely sure why it supposes stringCompare should be a constant…

And the line where it is mad about this being instantiated is:

if(masterList->artistMap.count(songArtist) == 0) 

artistMap being an stl::map with a string key.

I’m not sure where I’m going wrong. I attempted to change the bool operator() parameters to const, as it appears that it’s complaining about some sort of non-constant parameter passing. This didn’t work, nor did changing ‘bool operator()’ to ‘const bool operator()’.

As far as I know, strcasecmp is a const function so should case whether I pass it non-constant or constant parameters (c_str() also being const), so I’m not exactly certain where I’m going wrong.

I’ve googled similar issues but I still can’t quite make sense of the issue from what I’ve seen both on stackoverflow and a couple other places.

The datatype where I’m using this is:

map<string, set<song, setSongCompare>*,stringCompare > artistMap;
  • 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-31T13:06:21+00:00Added an answer on May 31, 2026 at 1:06 pm

    Two things:

    1. Define your bool operator() as const. It’s just a good practice. This tells the compiler that this function will not have side-effects on the member variables of the class.

    2. Add const & qualifiers to the lhs and rhs arguments. Passing constant references instead of copying memory all over the place is also good practice. By declaring references as const you’re telling compiler that this function should not have side-effects on the referenced objects.

    Your operator() should look as follows:

    bool operator() (const string &lhs, const string &rhs) const 
    {
      return strcasecmp(lhs.c_str(), rhs.c_str())  < 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.