#include<vector>#include<iostream>template<typenameT>classDynamic2DArray{std::vector<std::vector<T>>m_data;public:Dynamic2DArray(introwCount,intcolCount){m_data.resize(rowCount);for(auto&item:m_data){item.resize(colCount);}}intRowCount()const{return(int)m_data.size();}intColCount()const{if(m_data.size()>0){return(int)m_data[0].size();}return0;}std::vector<T>&operator[](introwIdx){if(rowIdx>=0&&rowIdx<(int)m_data.size())returnm_data[rowIdx];throwstd::runtime_error("out of index");}voidRemoveLastRow(){if(m_data.empty()==false)m_data.erase(m_data.end()-1);}voidRemoveLastColumn(){for(auto&item:m_data){if(item.empty()==false)item.erase(item.end()-1);}}voidPrintData(){intcolCount=ColCount();for(introw=0;row<(int)m_data.size();++row){for(intcol=0;col<colCount;++col){std::cout<<m_data[row][col]<<" ";}std::cout<<std::endl;}}};