#include using namespace std; //Suuruskontrolliga massiiv template class Massiiv { static const int suurus=100; T A[suurus]; public: T& operator[](int indeks) { if(indeks < 0 || indeks >= suurus){ cout << "vigane indeks\n" << endl; exit(1); //automaatne katkestus } return A[indeks]; } }; int main() { Massiiv im; Massiiv fm; for(int i = 0; i < 10; i++) { im[i] = i * i; fm[i] = i/2.0; } for(int j = 0; j < 10; j++) cout << j << ": " << im[j] << ", " << fm[j] << endl; //vigane katse im[1000]=7; //täitmine katkestatakse cout << im[1000] << endl; } /* D:\kodu\0309\oma>a 0: 0, 0 1: 1, 0.5 2: 4, 1 3: 9, 1.5 4: 16, 2 5: 25, 2.5 6: 36, 3 7: 49, 3.5 8: 64, 4 9: 81, 4.5 vigane indeks */