Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun-barr!texsun!pollux!ti-csl!m2!neath From: neath@solar-1.stars.flab.Fujitsu.JUNET Newsgroups: comp.lang.c++ Subject: operator[][]? Message-ID: Date: 15 May 89 06:42:30 GMT Sender: news@ti-csl.csc.ti.com Distribution: comp.lang.c++ Organization: Texas Instruments Data Systems Group, Austin TX Lines: 43 I am trying to determine what support there is in C++ for multi-dimensional arrays within a class. For example, the following class definition attempts to implement an array of pointers to vectors. Now, I know that I can overload operator[], but what I would really like to be able to do is overload the ficticious operator[][]. How can I achieve this functionality? Am I missing something very obvious? typedef int Type class C { private: int r, c; Type** data; public: X (int row, int col) { this->r = row; this->c = col; this->data = new Type* [row]; for (int i = 0; i < col; i++) this->data[i] = new Type [col]; } ~X () { for (int i = 0; i < r; i++) delete this->data[i]; delete this->data; } inline Type* operator[] (int row) { return this->data[row]; } inline Type& operator[][] (int row, int col) { return this->data[row][col]; } }; Regards Martin Neath ------------------------------------------------------------------------ DISCLAIMER: As always, the opinions expressed above are strictly my own and do not reflect those of my employer, Texas Instruments. ------------------------------------------------------------------------