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?
The code presents several problems
EDIT: I believe you either have:
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:
where localBusses is assumed to be of type:
std::map<string, AbstractBus*>(the only viable way if AbstractBus is abstract)