1

I have a 2d version of valarray called matrix. I want to access one column of it and use it as the left value outside of the class. The IDE gives me the following error on the return line. I guess [] operator of valarray returns an intermediate array and should be used immediately? How to fix this? Thank you

Non-const lvalue reference to type 'slice_array<[...]>' cannot bind to a temporary of type'slice_array<[...]>'

class matrix
{
public:
    matrix(int rows, int columns): _rows(rows), _columns(columns),storage(rows*columns) {}
    // Access a column
    slice_array<double> &operator()(int c){
        return storage[slice(c,_row,_columns)];
    }
private:
    int _rows;
    int _columns;
    valarray<double> storage;
Chris Zhang
  • 113
  • 1
  • 6

0 Answers0