[C++] Add map item passed in by reference

Started by
0 comments, last by SiCrane 13 years, 6 months ago
Why doesn't the following work? Searched everywhere. I want to pass the map in by reference so it doesn't copy it over. Why can't I add an item to the map?

bool Texture2D::ParseTextureAtlas(const string& fileName, const map<string, ImageDef>& imageMap){    imageMap["whatever"] = ImageDef(...);    return true;}
Advertisement
Because you're using a const reference to the map. If you want to modify it, use a non-const reference.

This topic is closed to new replies.

Advertisement