I'm using the header file below. I'm a little confused about how to store any matrices I create...
If I do:
int main()
{
Matrix A(2, 3);
Matrix B(3);
return 0;
}
Matrix::Matrix(int mdim_, int ndim_)
{
data_.resize (mdim_*ndim_);
for (int i = 0; i < mdim_*ndim_; i++)
{
data_[i] = 0;
}
}
Matrix::Matrix(int ndim_)
{
data_.resize (ndim_*ndim_);
for (int i = 0; i < ndim_*ndim_; i++)
{
data_[i] = 0;
}
}
Then does this create 2 separate matrices stored in data_? Or will Matrix B just overide the data in Matrix A? And if this is the case how would I get around this? (the header needs to remain unchanged).
Thanks in advance!
Header file:
#include<string>
#include<vector>
class Matrix {
public:
Matrix(int mdim, int ndim);
// Create a zero matrix with mdim rows and ndim columns
Matrix(int ndim);
// Create an zero ndim x ndim matrix
void Add(Matrix b);
// Add Matrix b to this matrix
void Subtract(Matrix b);
// Subtract b from this matrix
private:
int mdim_; // Number of rows of matrix
int ndim_; // Number of columns of matrix
std::vector<double> data_; // Vector storing the matrix data
};