template <typename T>
class CTArry
{
public:
CTArry(int nCol,int nRow):m_nCol(nCol),m_nRow(nRow)
{
m_nCol = nCol;
m_nRow = nRow;
Mallocal();
}
CTArry()
{
m_pData = NULL;
}
~CTArry()
{
MFree();
}
T* const operator[](int i)
{
return &m_pData[i*m_nCol];
}
const CTArry<T> & operator=(const CTArry<T>& o)
{
this->m_nRow = o.m_nRow;
this->m_nCol = o.m_nCol;
MFree();
Mallocal();
return *this;
}
int GetColCount()
{
return m_nCol;
}
int GetRowCount()
{
return m_nRow;
}
private:
void Mallocal()
{
m_pData = new T[m_nCol*m_nRow];
}
void MFree()
{
if (m_pData)
{
delete[] m_pData;
m_pData = NULL;
}
}
private:
int m_nCol;
int m_nRow;
T* m_pData;
};
重载二维数组
最新推荐文章于 2023-12-10 13:44:21 发布