The problem is that your operator returns by value:
float operator[] (int i);
When you pass the result of this directly to operator>>
, you are passing a temporary, and this operator needs an lvalue reference, something it is allowed to modify. Technically speaking, you cannot bind an rvalue reference (the temporary) to a non-const reference in standard C++.
So, change the operator to return a reference:
float& operator[] (int i);
It is common practice to provide a const
overload, returning a const
reference:
const float& operator[] (int i) const;