Slices and arrays problems?
Damian
damianday at hotmail.co.uk
Mon Jul 1 10:34:37 PDT 2013
void testref(ref int[] arr)
{
arr[0] = 1;
}
void test(int[] arr)
{
arr[0] = 1;
}
void main()
{
//int[] buffer1 = new int[4]; // This works
int[4] buffer1; // This doesn't
int[4] buffer2;
testref(buffer1);
test(buffer2);
assert(buffer1[0] == 1);
assert(buffer2[0] == 1);
}
I'm not sure why my code doesn't work?? Isn't the buffer just an
array with a fixed length? DMD is telling me 'buffer1 is not an
lvalue'. The non ref version works fine?!
More information about the Digitalmars-d-learn
mailing list