tags:

views:

85

answers:

1

I'm having problems with this call:

m_baseMap.find(baseName)->second->AddVehicale(vehicaleToAdd);

There's a red line under m_baseMap, the error is : "the object has type qualifiers that are not compatible with the member function". The base map is defined as the following:

map <string, const Base*> m_baseMap;

How can I fix it?

+2  A: 

The issue is not with the find() but with the call AddVehicale because the map specifies const Base*. You either need to make the map be map<string, Base *> or make sure AddVehicale is a const method (which means you are promising not to modify the object pointed to in the map) e.g. void Base::AddVehicale(Vehicale &v) const;

As far as I know, the compiler will choose whether to use the const find or the non-const find based on whether the map itself is const at the time (like if you have a const reference to the map)

P.S. Vehicale is spelled Vehicle (I use google to spell check if I'm not sure, search for the word and it will suggest the correct spelling)

MattSmith
i can't make the AddVehicle const, what do you mean "make the map be map"?
Roy Gavrielov
It should have been map<string, Base *> (without the const)
MattSmith
@Matt: Liberal use of backticks can help with disappearing template argument lists :-).
James McNellis
@Roy your member function `AddVehicale()` does not guarantee that it doesn't change its object. To make this guarantee you need to sign it as `AddVicale(...) const;` Alternatively, change the map to `map<string, Base*>`.
wilhelmtell