I’m learning boost and I wanted to rewrite my Matrix class. Instead of for loops I wanted to use BOOST_FOREACH, however I have some problems with operator overloading.
This is the original version of overloading operator /=
template<typename T>
Matrix<T> Matrix<T>::operator /= ( double varValue)
{
for (int i=0;i<this->rows;i++)
{
for (int j=0;j<this->columns;j++)
{
datavector.at(i).at(j) /= varValue;
}
}
return *this;
}
I wanted to change code above into something like this
template<typename T>
Matrix<T> Matrix<T>::operator /= ( double varValue)
{
BOOST_FOREACH(vector<T> row,datavector)
{
BOOST_FOREACH(T item,row)
{
item /= varValue;
}
}
}
However I constantly get an error
T: illegal use of this type as
expression
Is there any way to fix that?
You need to use a reference (based on the example at http://www.boost.org/doc/libs/1_39_0/doc/html/foreach.html). Also, you were missing a return statement: