Mail Archives: djgpp/1998/01/19/20:00:36
The reason your code is crashing is probably that the vector<T>'s inside
vector< vector<T> > 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<T> 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 -
- Raw text -