Skip to content

Commit

Permalink
operator *= and /= have to pass rhs by value because a const ref that…
Browse files Browse the repository at this point in the history
… aliases one of the elements of the vector/matrix causes failure (the referenced value changes when that element of vector/matrix is modified)
  • Loading branch information
twd20g committed Sep 5, 2012
1 parent b8bd385 commit eed7ed6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/matrix.hh
Expand Up @@ -200,7 +200,7 @@ public:
///@name operations on the matrix
///@{

Matrix& operator*=(const Precision& rhs)
Matrix& operator*=(const Precision rhs)
{
for(int r=0; r < num_rows(); r++)
for(int c=0; c < num_cols(); c++)
Expand All @@ -209,7 +209,7 @@ public:
return *this;
}

Matrix& operator/=(const Precision& rhs)
Matrix& operator/=(const Precision rhs)
{
for(int r=0; r < num_rows(); r++)
for(int c=0; c < num_cols(); c++)
Expand Down
4 changes: 2 additions & 2 deletions internal/vector.hh
Expand Up @@ -281,14 +281,14 @@ public:
/// @{

/// divide this vector by a constant
Vector& operator/=(const Precision& rhs) {
Vector& operator/=(const Precision rhs) {
for(int i=0; i<size(); i++)
(*this)[i]/=rhs;
return *this;
}

/// multiply this vector by a constant
Vector& operator*=(const Precision& rhs) {
Vector& operator*=(const Precision rhs) {
for(int i=0; i<size(); i++)
(*this)[i]*=rhs;
return *this;
Expand Down

0 comments on commit eed7ed6

Please sign in to comment.