Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!usc!rutgers!columbia!cubmol!ping From: ping@cubmol.BIO.COLUMBIA.EDU (Shiping Zhang) Newsgroups: comp.lang.c++ Subject: multi-dimensional vector Message-ID: <332@cubmol.BIO.COLUMBIA.EDU> Date: 5 Sep 89 03:10:50 GMT Reply-To: ping@cubmol.UUCP (Shiping Zhang) Organization: Dept. of Biology, Columbia Univ., New York, NY Lines: 76 The following is a one-dimensional vector (very simple) class intv { int sz; int *v; public: intv(); ~intv(); void set_size(int); int& operator[](int); }; intv::~intv() { delete v; } intv::intv() { sz=0; v = NULL; } void intv::set_size(int len) { int *t=new int[len]; for(long i=0;i=sz) { set_size(sz+LENGTH); // LENGTH is a constant } return v[i]; } // an example of using intv #define LENGTH 5; #include #include "intv.h" main() { intv a1; for(int i=0;i<10;i++) a1[i]=i; for(i=0;i<20;i++) cout << a1[i]*2; //a1 can be used without worrying its rang } Now the question is if there is a way to define a multi-dimensional vector which can be used freely without concern about boundry, for example, as following: //... // suppose intmv is defined as a vector, like intv above intmv a2[4][4]; // now define a 2d array of intmv ??? int i,k; for(i=0;i<4;i++) for(k=0;k<4;k++) a2[i][k][i*4+k]=i*k; // a2 being used freely // without checking the rang of // its 3rd dimemsion ??? Is this possible or legal? If yes, how to define intmv? I appreciate any help about this matter. Thanks. -ping