"not an lvalue"

Peter Alexander peter.alexander.au at gmail.com
Sun May 1 07:01:22 PDT 2011


On 1/05/11 2:30 PM, CrypticMetaphor wrote:
> Hi, I've been away from D for a while, but now I'm back and I'm stuck
> with an compile time error.
>
> I've got a Matrix33 class and a Vector3 class, but something is wrong
> with the way I return my Vector3 in my matrix class:
>
> If I do this I get an error:
>
> Matrix33 mtest = new Matrix33();
> mtest.SetIdentity();
> Vector3 test1 = new Vector3(0, 0, 0);
> Vector3 test2 = test + mtest.GetColumn(2);
>
> I get the error "Error: mtest.GetColumn(x) is not an lvalue"
>
> But the following works:
>
> Matrix33 mtest = new Matrix33();
> mtest.SetIdentity();
> Vector3 test1 = new Vector3(0, 0, 0);
> Vector3 temp = mtest.GetColumn(2);
> Vector3 test2 = test + temp;
>
> // GetColumn method
> Matrix33
> {
> // ...
>
> /// Get a matrix column, horizontal line
> Vector3 GetColumn(uint index)
> {
> assert(!(index > 2), "index is too high");
> return new Vector3(cell[index * 3], cell[index * 3 + 1], cell[index * 3
> + 2]);
> }
> // ...
> }
>
> My questions:
> What changes do I have to make to make the first example compile?

My guess is that your Vector3.opBinary!"+" is taking "ref" arguments 
instead of just taking them by value. Can you show us that function?


More information about the Digitalmars-d-learn mailing list