```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 ``` ```// // JavaScript みたいな配列に今一歩 // template class TVar { public: V val; TVar(): val(0) {} TVar(V v): val(v) {} TVar(const TVar &var) { val = var.val; } bool operator==(const V &v) { return val == v; } TVar& operator=(V v) { val = v; return *this; } V& operator=(TVar &var) { return var.val; } }; template class TArray { TVar *ptr; void copy(const TArray &ar) { ptr = ar.ptr; length = ar.length; const_cast(&ar)->ptr = NULL; // コピコン対策 } public: int length; // 書き換え出来てしまうのが格好悪いが ~TArray() { if(ptr) delete [] ptr; } TArray(): ptr(0) {} TArray(int i) { ptr = new TVar[i]; memset(ptr, 0, i*sizeof(T)); length = i; } TArray(const TArray &ar) { copy(ar); } TArray& operator=(const TArray &ar) { copy(ar); return *this; } TVar& operator[](int i) { if(i < length) return ptr[i]; TVar *tmp = new TVar[i+1]; memset(tmp, 0, (i+1) * sizeof(TVar*)); if(length) { memcpy(tmp, ptr, length * sizeof(TVar*)); delete [] ptr; } length = i+1; ptr = tmp; return ptr[i]; } }; typedef TArray Array; // --------------------------------------------------------- int main() { Array ar = Array(10); for(int i=0;i
 ```1 2 3 4 5 6 7 8 9 10 11 ``` ```0 1 2 3 4 5! ... 5 6 7 8 9 100 ```