I can't get passing an array by reference to work anymore...
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Sep 24 21:42:16 PDT 2015
On 09/24/2015 09:14 PM, Mike Parker wrote:
> I'm seeing the same error, but I haven't yet determined why.
It is because rvalues cannot be bound to 'ref' parameters:
void quickSort(ref int[] arr) {
// ...
quickSort(arr[0..wall]); // This slice is rvalue
quickSort(arr[wall+1..$]); // ditto
}
As it has already been said, there is no reason for the ref for this
function but the compilation error can be removed by making them lvalues:
auto left = arr[0..wall]; // now lvalue
quickSort(left);
auto right = arr[wall+1..$]; // ditto
quickSort(right);
Then it will expose another problem with the code. ;)
Ali
More information about the Digitalmars-d-learn
mailing list