Hi everyone,
I'm writing a class that holds a matrix (of double values), represented as vector<vector<double>>
;
I want to implement the operator=
, to re-fill my matrix with the details of a given sparse matrix. I'm writing the following code:
RegMatrix& RegMatrix::operator=(const SparseMatrix rhs){
if(*this != rhs){
_matrix.clear();
_matrix.resize(rhs.getRow());
int i;
for(i=0;i<rhs.getRow();++i){
_matrix.at(i).resize(rhs.getCol());
}
for(i=0;i<rhs.getSize();++i){
Element e = rhs.getElement(i);
_matrix[e._row][e._col] = e._val;
}
}
return *this;
}
Does the resize()
method fill automatically the vector with zeros?
Is my implementation ok?