On Dec 23, 10:09 pm, Mark <mnbaya...@gmail.com> wrote:
> I'm trying to figure out the best way to go about doing this.
> I have a "map" for a game, which I'd like to store in a matrix. Some
> cells will be empty (NULL), and some will hold objects.
> I need a matrix so that I can quickly find neighboring cells.
> However, when create this map, I don't know what size it is going to
> be, so it needs to be expandable. I also don't know which direction
> it's going to grow in, so starting at [0][0] and expanding as
> necessary won't work either, because I may later need to use [-1][0].
> I don't really care if the indices are re-written if I try to access a
> negative index. (ie, if I try to insert something into [-1][0], if it
> increased all the indices by 1 so it didn't have a negative index,
> that would be fine).
> I just need something that's simple to implement, and preferably has
> little overhead. I was contemplating using something like
> std::vector<vector<myClass> > but that wouldn't fill the negative
> index requirement, would it? Are there any other suggestions?
You could build your own dynamically sizing array (or derive of vector
and override) and let your base ptr point to the middle of the array
(then you could negative index up to numElementsOf(array)/2.
See:
http://msdn2.microsoft.com/en-us/lib...c4(VS.80).aspx
I'm sure if you dig around the net, you can find an automatically
increasing array (dynarray) or you could use CArray in MFC or as
mentioned previously std::vector (with derivation).
Hope that s.