#include <QtCore/QCoreApplication>
#include <QtDebug>
template <typename T> class DynArray2D
{
public:
DynArray2D(int n, int m)
{
_n = n;
_array = new T*[n];
for(int i = 0; i < n; i++)
_array[i]= new T[m];
}
void setValue(int n, int m, T v){_array[n][m]=v;}
T getValue(int n, int m){return _array[n][m];}
~DynArray2D(){
for(int i=0; i < _n;i++)
delete [] _array[i];
delete [] _array;
}
private:
T **_array;
int _n;
};
int main(int argc, char *argv[])
{
DynArray2D<int> dynIntArray(3,4);
dynIntArray.setValue(1,2,666);
qDebug()<< dynIntArray.getValue(1,2);
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QtDebug>
template <typename T> class DynArray2D
{
public:
DynArray2D(int n, int m)
{
_n = n;
_array = new T*[n];
for(int i = 0; i < n; i++)
_array[i]= new T[m];
}
void setValue(int n, int m, T v){_array[n][m]=v;}
T getValue(int n, int m){return _array[n][m];}
~DynArray2D(){
for(int i=0; i < _n;i++)
delete [] _array[i];
delete [] _array;
}
private:
T **_array;
int _n;
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
DynArray2D<int> dynIntArray(3,4);
dynIntArray.setValue(1,2,666);
qDebug()<< dynIntArray.getValue(1,2);
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks