开发者

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:

  1. Get rid of the asterisk: Sync* currS = _syncList.find(sync_id)->second;
  2. Be sure that find() actually finds an element (or else you need to check the return value of find() for map<...>::end).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜