Hello, I built a 2-D array with a single dynamic array and a dynamic array inside each one of those. But now I want to build a 2D array inside some of those slots.
I know this is some inception level stuff. But any help would be greatly appreciated.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <cmath>
usingnamespace std;
class Row
{
private:
int cols; // number of columns (array size)
bool *table; // single dimension array of 0's
public:
Row(); //Default constructor
Row(int); //Constructor with columns parameter
~Row(); //Destructor
int getRows() {return cols;} //Get size of rows
void setRows(int newRows) {cols = newRows;} // Sets the size of rows
bool getEl(int y) {return table[y];} // Gets elements in row location
void setEl(int); // sets the element in the row to true
void setEl(int,int);
};
#include "Row.h"
Row::Row() //Default constructor
{
cols = 9;
table = newbool[cols];
for(int i = 0; i < cols; i++)
{
table[i] = 0;
}
}
Row::Row(int newRow) //Constructor with columns parameter
{
cols = newRow;
table = newbool[cols];
for(int i = 0; i < cols; i++)
{
table[i] = 0;
}
}
void Row::setEl(int y) // sets the element in the row to true
{
table[y] = 1;
}
void Row::setEl(int y,int value)
{
table[y] = value;
}
Row::~Row() //Destructor
{
delete [] table;
}
Cols.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include "Row.h"
class Cols : public Row
{
private:
int szCols; // size of columns
int szRows; // size of rows
public:
Row **level; // 2-D array to construct where rooms are
Cols(); // Default Constructor
Cols(int,int); //Constructor with rows and columns parameter
~Cols(); //Destructor
int getSzCols() {return szCols;} // Get Column size
int getSzRows() {return szRows;} // Get Rows size
bool getData(int,int); // Get the data from the level array
void setEl(int,int);
};
Can't figure out what you want.
If I understand correctly, are you trying want to put a row into some columns, and another 2d array into some other columns?
If that's the case, since you have a class for each dimension, you could just create another 2d array class which inherits the Row class.
A little bit terrible, but that is based on your code.