actually, the two [] are superimposed. For more information, see Code .
# Include <iostream> <br/> # include <string> </P> <p> using namespace STD; </P> <p> template <class T> class arr; <br/> template <class T> class arrbody <br/>{< br/> PRIVATE: <br/> friend class arr <t>; <br/> T * data; <br/> int row, Col, current_row; <br/> arrbody (int r, int C, t d): Row (R ), COL (c) <br/>{< br/> DATA = new T [R * C]; <br/> current_row =-1; <br/> for (int K = 0; k <r * C; k ++) // initialize data. The default value is 0. <br/> data [k] = D; <br/>} <Br/> Public: <br/> T & operator [] (Int J) // reload the 2nd [] No. <br/>{< br/> If (j> = 0 & J <col) <br/> return data [current_row * Col + J]; <br/>}< br/> ~ Arrbody () {Delete [] data ;}< br/> }; </P> <p> template <class T> class arr <br/>{< br/> PRIVATE: <br/> arrbody <t> tbody; <br/> Public: <br/> arrbody <t> & operator [] (int I) // reload the first [] No. <br/>{< br/> if (I >=0 & I <tbody. row) <br/> tbody. current_row = I; <br/> return tbody; <br/>}< br/> Arr (int I, Int J, t d = 0): tbody (I, j, d) {}< br/>}; </P> <p> void main () <br/>{< br/> arr <int> A (10, 20 ); <br/> arr <double> B (5, 5); <br/> cout <A [5] [5] <Endl; <br/>}< br/>