Zach
Zach

Reputation: 537

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?

Upvotes: 0

Views: 83

Answers (1)

NPE
NPE

Reputation: 500893

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).

Upvotes: 3

Related Questions