-1

I'm currently trying to implement a class around a valarray object and i get a exception when trying to run:

class TestClass
{
    public:
    valarray<int> va;
    TestClass() { va.resize(5, 1); }
    slice_array<int>& get_slice()
    {
        return va[slice(0, 3, 2)];
    }
};

//In main():

TestClass obj;

slice_array<int>& ref = obj.va[slice(0,3,2)];

ref = -1;               //OK
obj.get_slice() = -1;   //Throws exception

Aren't the two assignments the same thing?

DarzVader
  • 21
  • 1

1 Answers1

0

I solved it myself: It seems that a valarray[slice(int, int, int)] is not an lvalue or is temporary, so it's not allowed to initialize a reference with such an object (oddly enough, VS2012 allows to do so in some cases).

DarzVader
  • 21
  • 1