I'm having this weird problem: when my program reach this method:
//Returns the transpose matrix of this one
RegMatrix RegMatrix::transpose() const{
RegMatrix result(numCol,numRow);
int i,j;
for(i=0;i<numRow;++i)
for(j=0;j<numCol;++j){
result._matrix[j][i] = _matrix[i][j];
}
return result;
}
it suddenly crashes...
When i ran it with my VS debugger, it looked just all fine, the new matrix was filled with the relevant values, till the line return result;
that from some mysterious reason returned an empty matrix vector.
Where do i go wrong??
Here is my implementation for the copy constructor:
//CCtor of RegMatrix
RegMatrix::RegMatrix(const RegMatrix &other): numRow(other.getRow()), numCol(other.getCol()){
//Create
_matrix = vector<vector<MyDouble> >(other.getRow());
int i,j;
for(i=0; i < numRow; i++)
_matrix[i] = vector<MyDouble>(other.getCol());
//Copy Matrix
for(i=0;i<numRow; ++i){
for(j=0;j<numCol; ++j){
_matrix[i][j] = other._matrix[i][j];
}
}
}
My assignment operator implementation:
//RegMatrix = RegMatrix
RegMatrix& RegMatrix::operator=(const RegMatrix rhs){
assert(numRow == rhs.getRow() && numCol == rhs.getCol());
if(*this != rhs){
int i,j;
for(i=0;i<numRow;++i)
for(j=0;j<numCol;++j){
_matrix[i][j] = rhs._matrix[i][j];
}
}
return *this;
}