From: Charles Krug Newsgroups: comp.os.msdos.djgpp,comp.lang.c++ Subject: Re: 2d Matrix class with conventional c/c++ element access semantics Date: Tue, 20 Jan 1998 10:02:08 -0500 Lines: 53 Message-ID: <34C4BC70.8E63DBE0@pentek.com> References: <34C36C45 DOT 24966424 AT pentek DOT com> <199801200038 DOT RAA49356 AT huey DOT cadvision DOT com> NNTP-Posting-Host: mail.pentek.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Thank you, groups, for your suggestions. My problem was confusing two different methods of construction. I did not consider using a single vector with an accessor method based on (m, n). My goal was a drop-in replacement for code that operates on conventional C 2d arrays. Hence, the accessor method using [m][n] was essential. Although I wrote a multiplication method to test my accessor methods, I do not expect to use this class for matrix math. I am using the code to implement an adjacency matrix, which I am using to solve a digital logic problem. Since my adjacency matrix code operates on conventional C arrays, preserving accessor semantics was extremely important to me. Your milage may vary. Here is the class interface: #include template class matrix { private: // Things that I want to avoid, generally speaking public: matrix() : rows() {} matrix(const unsigned int nor, const unsigned int noc, const T val = T()) :rows(nor, vector(noc, val)) {} matrix(const matrix & v) :rows(v.rows) {} matrix & operator = (const matrix & val) { if (&val == this) return *this; rows = val.rows; return *this; } ~matrix() {} vector & operator [ ] (unsigned int i) { return rows[i];} unsigned int numberOfRows() const { return rows.size(); } unsigned int numberOfColumns () const { return rows[0].size(); } protected: vector > rows; }; -- Charles Krug, Jr.