Get Problem With Map!

//I wanna make a map which take a Vector2 as key, and int as value, also with a //compareFunction.


class Vector2{
public:
int x=-99999;
int y=-99999;
Vector2(int _x, int _y) {
x = _x;
y = _y;
}
Vector2() {}
};

int squrePerRow=10;
bool fncomp(Vector2 first, Vector2 second) { return (first.x < second.x); }
bool(*fn_pt)(Vector2, Vector2) = fncomp;
map<Vector2, int, bool(*)(Vector2, Vector2)> allNodes(fn_pt);

void SetUpNode() {
for (int y = 0; y < squrePerRow; ++y) {
for (int x = 0; x < squrePerRow; ++x) {
Vector2 position = Vector2(x,y);
int cost = 5;
allNodes.insert(pair<Vector2,int>(position,cost));
}
}
}

When I setUpNode, only the 10 node can be insert to the map.
I am not that familiar with map. what i did rwong? How can I solve it?
Last edited on
The map doesn't store duplicate keys. Your comparison function fncomp only compares the x coordinates so all vectors that has the same x value will be considered equal, no matter what the value of y is. You try to insert 100 elements but there are only 10 unique x values so that is why only 10 elements are inserted.
Last edited on
Topic archived. No new replies allowed.