vendredi 29 juillet 2016

Wrapping std::map and provide pointer to element

I am using a library which offers a function foo(Widget*).

My Widgets are stored in

struct WidgetManager {

  std::map<int, Widget> dict;

  ??? getWidget(int id);

}

Originally I stored (raw) Widget pointers in the std::map just because it was convenient to pass them to foo. If I wan't to store the actual Widgets in the map, what should the return type of getWidget be so that I can pass a pointer of the Widget to foo?

I am compelled to make it of type iterator, but I don't like that I have to access itr->second to get the Widget(pointer).

Aucun commentaire:

Enregistrer un commentaire