Hey there, new to the forums so hi!

I've been trying to sort this problem out for quite a while - in fact in some forms years...

It's for a game, but is a generic map problem so I'd be interested in how people solve this. I've got an class (cGameObject) that represents any object in the game / system. Each object is positioned at an X and Y coordinate (thankfully only 2D!) with a width and a height.

Currently, I'm using an STL map to handle this, as such:

typedef std::map < int, cGameObject * > MapYAxis;
typedef std::map < int, MapYAxis > MapXAxis;

So, it's a Map of an Int to a Map of an Int to a Game Object Ptr. That gives me things like
For ( x = Map.LowerBound(1); x < Map.UpperBound(100); x++)
(Pseudo, obviously).

However, this doesn't do collision checking. If I wanted to add an object and make sure it did not overlap another object I'd need to check that no other object overlapped any of the 4 corners, by doing a search on X and Y plus the width and height of the biggest object in the game, and THEN I'd still have to compare each object to make sure the points overlapped or not.

How do other people accomplish a similar goal? Or is it really not going to have an elegant solution? What I'd like is a way to do something like this:

OOOOOOOOOOOO
OOOOOOOOOOOO
OXXXXXXOOOOOO
OXXXXXXOOOOOO
OXXXXXXOOOOOO
OOOOOOOOOOOO

Where X's are all pointers to the same object. But, this doesn't work - firstly, it's costly (in inserting, updating, deleting, etc) and secondly because, when iterating through the map to output objects data, I'd get the same data multiple times, so would THEN have to keep track of which objects I've already displayed!!

Any help much appreciated! :-)

Mark