Search code examples
c++objectreferencemultimap

Reference to multimap object


Is it possible to return a reference of an object inside a multimap? This is what I'm trying:

return &this->noteList.find(key)->second;

But I'm getting Non-const lvalue reference to type 'Note' cannot bind to a temporary of type 'Note *'so I was wondering if it's even possible, and if so, how? notelist is the multimap and it has Noteobjects inside it.


Solution

  • this->noteList.find(key)->second already gives you a reference to an object inside a multimap (if this->noteList is a multimap).

    By prefixing that expression with an ampersand (&), you get a pointer to such an object (if that operator is not overloaded)