This error:
error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility 216
occurs on this function’s only line:
void Animation::AddAnimation(std::string name, AnimationFrameSet& animation) {
_animations.insert(std::make_pair(name, animation));
}
_animations is a std::map<std::string, AnimationFrameSet>
AnimationFrameSet declares an operator=(…) and a copy constructor, but weirdly enough, the compiler says it fails on the attempted copying of const std::string…even though the string isn’t even being passed in as a const.
I can’t for the life of me figure out (or even remember! :P) why this is/should throwing/throw an error.
Thanks.
EDIT
The reason I’m a little confused why this is not working is that a different class uses a very similar implementation and it does not throw an error:
BITMAP* BitmapCache::GetBitmap(std::string filename) {
//Return NULL if a bad filename was passed.
if(filename.empty()) return NULL;
if(exists(filename.c_str()) == false) return NULL;
//Reduce incorrect results by forcing slash equality.
filename = fix_filename_slashes(&filename[0]);
//Clean the cache if it's dirty.
CleanCache();
//Search for requested BITMAP.
MapStrBmpIter _iter = _cache.find(filename);
//If found, return it.
if(_iter != _cache.end()) return _iter->second;
//Otherwise, create it, store it, then return it.
BITMAP* result = load_bmp(filename.c_str(), NULL);
if(result == NULL) return NULL;
/*Similar insert line, a non-const std::string that was passed in is passed to a std::make_pair(...) function*/
_cache.insert(std::make_pair(filename, result));
return result;
}
typedefs:
typedef std::map<std::string, BITMAP*> MapStrBmp;
typedef MapStrBmp::iterator MapStrBmpIter;
The reason why this is failing is because the std::map container you are using expects a const value as key value.
Check the documentation of std::map here.
Example: