I'm working on something very similar, so I think I could help you
I'd like to repeat what someone else already said:
lol wut?
Also, I am absolutely disgusted at the sight of a
Object***, do you really want to be known as a three star programmer ;-P ?
http://www.c2.com/cgi/wiki?ThreeStarProgrammer
Before you know it you'll be knowing nested #if #elsif macros and no one but you will be able to maintain your code :P.
May I suggest wrapping your "Field" in a class as well, and only using an array of Tile* of size m * n, and accessing your array elements using an overload
operator(). It will make things MUCH MUCH easier in the long run, there are also less pointer chases so it is more efficient.
Something like this:
Field.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#ifndef _FIELD_H_
#define _FIELD_H_
#include "Tile.h"
class Field
{
public:
typedef unsigned int size_type;
Field(size_type rows, size_type cols);
Field(const Field& other);
virtual ~Field();
Field& operator=(const Field& other);
Tile* operator()(size_type row, size_type col);
const Tile* operator()(size_type row, size_type col) const;
private:
Tile** grid;
size_type numRows, numCols;
};
#endif /* _FIELD_H_ */
| |
Field.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include "Field.h"
Field::Field(size_type rows, size_type cols) :
grid(new Tile*[numRows * numCols]), numRows(rows), numCols(cols)
{
//additional implementation ommited
}
Field::Field(const Field& other) :
grid(new Tile*[other.numRows * other.numCols]), numRows(other.numRows), numCols(other.numCols)
{
//additional implementation ommited
}
Field::~Field()
{
//additional implementation ommited
}
Field& Field::operator=(const Field& other)
{
if(this != &other)
{
//additional implementation ommited
}
return *this;
}
/** This is the important bit right here **/
Tile* Field::operator ()(size_type row, size_type col)
{
return grid[row * numCols + col];
}
const Tile* Field::operator ()(size_type row, size_type col) const
{
return grid[row * numCols + col];
}
| |