C
Charulatha Kalluri
Hi,
I'm implementing a Matrix class, as part of a project. This is the interface
I've designed:
class Matrix( )
{
private:
vector< vector<int> > m_Data;
pair<int, int> m_size;
public:
Matrix(unsigned int n);
Matrix(unsigned int m, unsigned int n);
~Matrix();
....................................
}
I have a couple of questions:
1. Is there a better way to model the data structure other than a vector of
vectors? I realize I can write up the Matrix class from scratch, but I want
to use STL containers.
2. If I use a vector of vectors, how would dynamic memory allocation work? I
don't fully understand how STL's vector handles memory. For example, to
resize a matrix, how would I "delete" the memory for the old matrix? Would
the 'resize' and 'clear' functions guarantee proper memory management,
without leaks?
Thanks in advance!!
-CK
I'm implementing a Matrix class, as part of a project. This is the interface
I've designed:
class Matrix( )
{
private:
vector< vector<int> > m_Data;
pair<int, int> m_size;
public:
Matrix(unsigned int n);
Matrix(unsigned int m, unsigned int n);
~Matrix();
....................................
}
I have a couple of questions:
1. Is there a better way to model the data structure other than a vector of
vectors? I realize I can write up the Matrix class from scratch, but I want
to use STL containers.
2. If I use a vector of vectors, how would dynamic memory allocation work? I
don't fully understand how STL's vector handles memory. For example, to
resize a matrix, how would I "delete" the memory for the old matrix? Would
the 'resize' and 'clear' functions guarantee proper memory management,
without leaks?
Thanks in advance!!
-CK