我想了解下面的代码是如何运行的。代理是从 mPtr 继承的吗?struct array 是否在 struct aproxy 中返回方法 aproxy?
struct aproxy {
aproxy( int & r ) : mPtr( & r ) {} // is this inheritance?
void operator = ( int n ) {
if ( n > 1 ) {
throw "not binary digit";
}
*mPtr = n;
}
int * mPtr;
};
struct array {
int mArray[10];
aproxy operator[]( int i) {
return aproxy( mArray[i] ); // what does this line do?
}
};
int main() {
try {
array a;
a[0] = 1;
a[0] = 42;
}
catch( const char * e ) {
cout << e << endl;
}
}