问题
填空题
下面程序编译时发现ma[3]=9错误,其原因是______。 #include<iostream.h> class FunArray { int*pa; //指向一个数组空问 int size; //数组元素个数 public: FunArray(int a[],int thesize):pa(a),size(thesize){} int Size( ){return size;} } }; void main( ) { int s[]={3,7,2,1,5,4}; FunArray ma(s,sizeof(s)/sizeof(int)); ma[3]=9; cout<<ma[3]<<endl; }
答案
参考答案:没有重载[]运算符
解析: ma不是一般的数组,而是一个新定义的类,尽管该类封装了一个数组,但新类并没有提供[]操作符的具体实现,因此是错误的。