Newsgroups: comp.os.msdos.djgpp,comp.lang.c++ Subject: Re: 2d Matrix class with conventional c/c++ element access semantics From: frenchc AT cadvision DOT com (Calvin French) References: <34C36C45 DOT 24966424 AT pentek DOT com> MIME-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII NNTP-Posting-Host: ts7ip236.cadvision.com Message-ID: <34c3f1ff.0@news.cadvision.com> Date: 20 Jan 98 00:38:23 GMT Organization: CADVision Development Corporation (http://www.cadvision.com/) Lines: 23 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk The reason your code is crashing is probably that the vector's inside vector< vector > aren't getting initialized (but I don't know). If I were you, i would do it much differently. Realize that by putting a vector inside a vector you are allowing functionality which isn't really normal for a matrix. For instance, to have one row longer than another. If I were you, I would do it this way: template< class T > class matrix { vector v; // internal data storage. unsigned int w, h; // dimensions of matrix. public: matrix( unsigned int W, unsigned int H ) : w(W), h(H), v(W*H) {}; // hoping this will init v correctly :) T& operator( unsigned int X, unsigned int Y ) { return v[ Y*w + X ]; }; }; That ought to give you the general idea. Just hope it works :) - Calvin -