Original Post
Alright...last question! I promise! My code works fine if I hard code an array of [15][10] (col x row). But when I use my dynamic array that you guys helped me make, it come out all gimped.
Soo...I assume its because the array is using row x col and I want col x row. So this is my array2D class, So my question is, how can i make this work with col, row instead of row,col. I've tried a few things, all of which didn't work. Thanks!!!
Soo...I assume its because the array is using row x col and I want col x row. So this is my array2D class,
#ifndef TwoDArray_H
#define TwoDArray_H
template <class T>
class Array2D
{
public:
//creates a new 2D array of [row][col]
void createArray(int row, int col);
//delete our array
void deleteArray();
//so we can do m(x,y). more flexible than [].
T& operator () ( int row, int col);
//how many colums and rows
int retnCol();
int retnRow();
int ARRAY_COLUMS;
int ARRAY_ROW;
//size in bytes
//int retnSize();
private:
//the actual array, which is really 1D
T *Array;
//how many Cols we have
};
template<class T> void Array2D<T>::createArray(int row, int col)
{
Array = new T[row * col];
ARRAY_COLUMS = col;
ARRAY_ROW = row;
}
template<class T> void Array2D<T>::deleteArray()
{
delete[] Array;
Array = NULL;
}
template<class T> T& Array2D<T>::operator () ( int row, int col)
{
return Array[row*ARRAY_COLUMS + col];
}
template<class T> int Array2D<T>::retnCol()
{
return MATRIX_COLUMS;
}
template<class T> int Array2D<T>::retnRow()
{
return MATRIX_ROW;
}
#endif