2019-02-27 16:21:34 +09:00
|
|
|
// DynArray2D.h
|
|
|
|
#ifndef DYNARRAY2D_H
|
|
|
|
#define DYNARRAY2D_H
|
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
// Code from
|
|
|
|
// https://www.qtcentre.org/threads/31440-two-dimensional-array-size-determined-dynamically Some
|
|
|
|
// code is fixed by j2doll
|
2019-02-27 16:21:34 +09:00
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
template <typename T>
|
|
|
|
class DynArray2D
|
2019-02-27 16:21:34 +09:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DynArray2D(int n, int m)
|
|
|
|
{
|
2023-09-04 00:46:33 -03:00
|
|
|
_n = n;
|
|
|
|
_array = new T *[n];
|
|
|
|
for (int i = 0; i < n; i++) {
|
2019-02-27 16:21:34 +09:00
|
|
|
_array[i] = new T[m];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
void setValue(int n, int m, T v) { _array[n][m] = v; }
|
2019-02-27 16:21:34 +09:00
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
T getValue(int n, int m) { return _array[n][m]; }
|
2019-02-27 16:21:34 +09:00
|
|
|
|
|
|
|
~DynArray2D()
|
|
|
|
{
|
2023-09-04 00:46:33 -03:00
|
|
|
for (int i = 0; i < _n; i++) {
|
|
|
|
delete[] _array[i];
|
2019-02-27 16:21:34 +09:00
|
|
|
}
|
2023-09-04 00:46:33 -03:00
|
|
|
delete[] _array;
|
2019-02-27 16:21:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T **_array;
|
|
|
|
int _n;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DYNARRAY2D_H
|