operator= 返回 void,應返回 Array& 支持鏈式賦值。operator+ 分配內存用 l(當前對象長度)而非 BIG(最大長度),導致越界。const 引用。class Array {
int *a; int l;
public:
Array() : a(nullptr), l(0) {}
Array(int x) : a(new int[x]), l(x) {
for (int i=0; i> a[i];
}
~Array() { delete[] a; }
// 拷貝構造
Array(const Array& rhs) : a(new int[rhs.l]), l(rhs.l) {
for (int i=0; i
operator= 返回 Array&,處理自賦值,釋放舊內存再分配新內存。operator+ 分配 maxLen,訪問時檢查下標邊界,超出視為 0。const,支持臨時對象綁定。