Compiling problems dealing map.find and initialization
I've written a class in c++ named 'Sync'. Then, i've created a map holding Sync objects, associated with syncID num, as follows:
map<int, Sync*> _syncList;
In one of my methods, I'm trying to search for an existing Sync object in my map, according to a given syncID number, as follows:
Sync* currS = *(_syncList.find(sync_id))->second;
I thought this would be neat, but then the compiler complained about this:
error: cannot convert ‘Sync’ to ‘Sync*’ in initialization
What can i do in order to fix this properly开发者_如何学运维?
Two things:
- Get rid of the asterisk:
Sync* currS = _syncList.find(sync_id)->second;
- Be sure that
find()
actually finds an element (or else you need to check the return value offind()
formap<...>::end
).
精彩评论