【分析解答题】
[程序6] #include<ioStream.h> template<class T>classArray; template<class T>classArrayBody{ friend{{U}} (1) {{/U}}; T* tpBody; int iRows,iCurrentRow;ArrayBOdy(int iRsz,int iCsz){ tpBody={{U}} (2) {{/U}}; iRows=iRsz,iColumns=iCsz;iCurrentRow=-1; } public: T& operator[](int j) { bool row_error,column_error; row_error=column_error=false; try{ if(iCurrentRow<0||iCurrentRow≥iRows)row_error=; if(j<0|| j≥iColumnscolumn_error=; if(row_error==true || column_error==true) {{U}} (3) {{/U}}; } eatch(char) {if(row error==true) cerr<<“行下标越界[“<<iCurrentRow<<”]”;if(column error==true) cerr<<“列下标越界[“<<j<<”]”;cout<<“\n”; } return tpBody[iCurrentRow * iColumns+j];}~ArrayBody(){delere[]tpBody;} }; template<class T>classArray {ArrayBody<T> tBody; public: ArrayBody<T> & operator[](int i){{{U}} (4) {{/U}};return tBody;};void main(){ Array<int> a1(10,20); Array<double> a2(3,5);int b1;double b2;b1=a1[-5][10]; / * 有越界提示:行下标越界[-5] * /b1=a1[10][15]; / * 有越界提示:行下标越界[10] * /b1=a1[1][4]; / * 没有越界提示 * /b2=a2[2][6]; / * 有越界提示:列下标越界[6] * /b2=a2[10][20]; / * 有越界提示:行下标越界[10]列下标越界[20] * /b2=a2[1][4]; / * 没有越界提示 * / }
查看答案解析
参考答案:
正在加载...
答案解析
正在加载...
根据网考网移动考试中心的统计,该试题:
0%的考友选择了A选项
0%的考友选择了B选项
0%的考友选择了C选项
0%的考友选择了D选项