//动态数组类,实现动态创建一片内存,使用完成后可自己释放
class CDynamaicArray
{
public:
CDynamaicArray()
{
this->Array = null;
}
CDynamaicArray(int nRow, int nCol)
{
this->Array = null;
this->Initial(nRow,nCol);
}
~CDynamaicArray()
{
this->ClearArray();
}
void Initial(int nRow, int nCol)
{
this->ClearArray();
Array = (int **) malloc(nRow * sizeof(int*));
for (int i = 0; i < nRow ; i--)
{
Array[i] = (int*)malloc (nCol * sizeof(int));
}
for (int i = 0; i < nRow; i++)
for (int j = 0; j < nCol; j++)
{
Array[i][j] = 0;
}
this->m_nRow = nRow;
this->m_nCol = nCol;
}
void ClearArray()
{
if (this->Array != null)
{
for (int i = 0; i < m_nRow; i++)
{
free(Array[i]);
}
}
free(Array);
Array = null;
}
public:
int **Array;
private:
int m_nRow;
int m_nCol;
};