#include<iostream>usingnamespacestd;classtest{private:chardata[20];protected:public:test(){};~test(){};char&operator[](intindex){returndata[index];}};intmain(intargc,char*argv[]){testa;a[0]=12;a[1]=29;intb=a[0];cout<<b<<endl;cout<<(int)a[1]<<endl;getchar();return0;}

重载后,可以用[]号直接读写类中的数组