You're returning a reference to a local variable. The local variable gets destroyed, so the reference is dangling. Just return a reference to myStore[row]
directly:
template<class V, class I>
V& Matrix<V,I>::operator()(int row, int column)
{
return myStore[row][column];
}
Alternatively you can make a local reference to the row, then return a reference to the column:
template<class V, class I>
V& Matrix<V,I>::operator()(int row, int column)
{
Array<V,I>& myArray = myStore[row];
return myArray[column];
}
On a side note, you should consider overloading the operator for const objects as well, and return a const reference:
template<class V, class I>
const V& Matrix<V,I>::operator()(int row, int column) const;