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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:43:27+00:00 2026-05-27T01:43:27+00:00

I am trying to implement the following method to get the bus corresponding to

  • 0

I am trying to implement the following method to get the bus corresponding to its name which is passed as a string to the method. Here AbstractBus is an abstract class which contains functionality of a bus. localBusses is a std::map

void getLocalBusByName(string& name, AbstractBus& bus) 
{
    bus =  localBusses.find(name)->second;
}

However, I am getting an error “no operator “=” matches these operands”
Can anyone explain what is wrong here and how can I correct it?

  • 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-27T01:43:28+00:00Added an answer on May 27, 2026 at 1:43 am

    The code presents several problems

    1. It does not handle the case when localBusses.find(…) doesn#t find a bus
    2. You seem to want to return a reference to the found bus. You should remember that references are aliases and they can bind only when declared and remain immutable afterwards. That is you cannot re-bind a reference to another object
    3. Following 2, the bus = … attempts to call the assignment operator to assign the found bus to the one refered to by the reference. The assignment operator does not exist or is not accessible. This is good so since having an assignment operator in this context is a bad idea and if present it would probably lead to slicing if the AbstractBus class would be instantiable (non-abstract).

    EDIT: I believe you either have:

    typedef std::map<string, AbstractBus*> tBussesMap;
    tBussesMap localBusses;
    

    or AbstractBus is not really abstract (does not contain any pure methods) (despite its name)

    In either case I assume however you have classes derived from AbstractBus. And getLocalBusByName has to provide for situations where no bus is found and avoid inadvertent slicing.

    So you should write getLocalBusByName method in the lines of:

    AbstractBus* 
    getLocalBusByName( const string& name )
    {
        tBussesMap::iterator it = localBusses.find(name);
    
        if ( it != localBusses.end() )
        {
            return it->second;
        }
    
        return nullptr;
    }
    

    where localBusses is assumed to be of type:std::map<string, AbstractBus*> (the only viable way if AbstractBus is abstract)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement routing such as the following: posts/535434/This-is-a-post-title posts/tagged/tags+here // Matches {controller}/{action}/{id}
I'm trying to implement the following method: void Ball::DrawOn(Graphics g); The method should draw
In c# I am trying to implement a method which I can use to
I got a little problem here guys. I'm trying to implement the following scenario:
I am trying to implement the jQuery Deferred.pipe() method for the following scenario: Add
im trying to implement a getBounds() method, but i cant get union to work;
I'm trying to implement the following mod_rewrite rule: host.com/developer/ => host.com/developer/index.py host.com/developer/branchX => host.com/developer/index.py?branch=branchX
I'm trying to implement XOR in javascript in the following way: // XOR validation
I'm trying to implement my own GenericIdentity implementation but keep receiving the following error
I'm trying to implement http://github.com/bengottlieb/Twitter-OAuth-iPhone/tree/master into my code. I'm following the Demo provided and

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.