Yeah... I did it like this instead:
Code:
#ifndef FIELD_H_INCLUDED
#define FIELD_H_INCLUDED
#include "object.h"
class field{
public:
int length, width, height;
object ****location;
field(int l = 1, int w = 1, int h = 1);
field(const field&);
~field();
};
#endif // FIELD_H_INCLUDED
Code:
#include "field.h"
field::field(int l, int w, int h) : length(l), width(w), height(h)
{
int i, j, k;
location = new object*** [length];
for(i = 0;i < length;i++)
{
location[i] = new object** [width];
for(j = 0;j < width;j++)
{
location[i][j] = new object* [height];
for(k = 0;k < height;k++)
location[i][j][k] = 0;
}
}
}
field::field(const field& f) : length(f.length), width(f.width), height(f.height)
{
int i, j, k;
location = new object*** [length];
for(i = 0;i < length;i++)
{
location[i] = new object** [width];
for(j = 0;j < width;j++)
{
location[i][j] = new object* [height];
for(k = 0;k < height;k++)
location[i][j][k] = f.location[i][j][k];
}
}
}
field::~field()
{
int i, j, k;
for(i = 0;i < length;i++)
{
for(j = 0;j < width;j++)
{
for(k = 0;k < height;k++)
if(location[i][j][k] != 0)
delete[] location[i][j][k];
delete[] location[i][j];
}
delete[] location[i];
}
delete[] location;
}
I realized I don't need vectors anyway. I won't have any reason to resize after defining and allocating it, so I guess I don't need all the extra bloat.
Thanks for the example though.