Reputation: 333
In this post Convert a multi_key map into a "normal" map joining the multiple keys
They suggest how to convert a multimap to the map by passing the values of the first to the second one. I tried that in my code, but it doesn't work:
multimap<double, Point>::iterator it;
for(it = _mapIntersectionVertices.begin(); it != _mapIntersectionVertices.end(); ++it)
{
_mapNewPoints[it->first].insert(it->second);
}
I get the error "no member named 'insert' in 'Point'" I don't know why, I am not trying to call a method, just following the example in the post. As a side thing I am not very comfortable with the fact they use the same iterator for the map and the multimap inside the for, but when using instead a map iterator it2 to do:
_mapNewPoints[it2->first].insert(it->second)
nothing changes
where i have the following attributes in some class I am trying to fill in.
multimap<double, Point> _mapIntersectionVertices;
map<double, Point> _mapNewPoints;
and the Point class is:
class Point
{
private:
Vector2d _coordinates; //using Eigen library
public:
int _label;
Point(const double x = 0.0, const double y = 0.0);
Point(Vector2d coordinates);
void setCoordinates(const double x, const double y) {_coordinates(x, y);}
const Vector2d& getCoordinates() const {return _coordinates;}
};
I want to copy the content of the multimap into the map, so that I can add more data to the later without messing with the first one and in a easier way than if _mapNewPoints were declared as a multimap( using the [] operator that is available for a map but not for a multimap).
How do I solve this?
Upvotes: 0
Views: 182
Reputation: 23792
_mapNewPoints[it->first].insert
would imply that Point
has an insert
method which is not the case. I believe you may want something like this:
for (it = _mapIntersectionVertices.begin(); it != _mapIntersectionVertices.end(); ++it)
{
_mapNewPoints.insert(*it);
}
Upvotes: 1