//--------------------------------------------------------------------------- // dyna2.cpp // Ohjelmalla demonstroidaan dynaamista taulukkoa // Vesa Lappalainen 5.3.2001 // #include #include class cTaulukko { int max_koko; int lkm; int *alkiot; public: cTaulukko(int ikoko) : max_koko(ikoko), lkm(0) { alkiot = new int[max_koko]; // malloc, calloc } ~cTaulukko() { delete [] alkiot; } // free void lisaa(int luku) { if ( lkm >= max_koko ) return; alkiot[lkm] = luku; // *(alkio + 2) = 7; <==> alkio[2] = 7; lkm++; } void tulosta() const; }; void cTaulukko::tulosta() const { int i; for (i=0; i