0
我想了解下面的代碼如何運行。從aproxy繼承mPtr?結構數組返回一個方法,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;
}
}