map find with custom object : map find « Map Multimap « C++






map find with custom object

  
#include <map>
#include <iostream>
using namespace std;

class Data
{
public:
  Data(int val = 0) { mVal = val; }
  int getVal() const { return mVal; }
  void setVal(int val) {mVal = val; }

protected:
  int mVal;
};

int main(int argc, char** argv)
{
  map<int, Data> dataMap;
  dataMap[1] = Data(4);
  dataMap[1] = Data(6);

  map<int, Data>::iterator it = dataMap.find(1);
  if (it != dataMap.end()) {
    it->second.setVal(100);
  }

  return (0);
}
  
    
  








Related examples in the same category

1.Map find
2.map: find_if
3.Find product in a map by its number
4.Find product in a map by its type
5.find all elements in a map by value
6.map look up
7.Find the value with a given key