On Friday, 25 September 2015 at 02:37:22 UTC, TheGag96 wrote:
So I'm just doing a small test program here:
http://pastebin.com/UYf2n6bP
(I'm making sure I know quicksort for my algorithms class, I
know functionally this won't work as-is)
I'm on Linux, 64-bit, DMD 2.068.1, and when I try to compile
this I'm getting:
quicksort.d(18): Error: function quicksort.quickSort (ref int[]
arr) is not callable using argument types (int[])
quicksort.d(19): Error: function quicksort.quickSort (ref int[]
arr) is not callable using argument types (int[])
No matter how I attempt to define the array test, it will never
allow me to pass it by reference no matter what. I even
copy-pasted some example code from here
(https://en.wikibooks.org/wiki/D_(The_Programming_Language)/d2/Pointers,_Pass-By-Reference_and_Static_Arrays#Pass_By_Reference, bottom of the page), and it gave the same error.
What's the problem here? I SWEAR I've passed arrays by
reference before just like this. Thanks guys.
Im not sure why but..
Are you sure that you want to pass the array by ref?
In D the type int[] is like struct { size_t length; int* ptr;}
which means you are accessing through a pointer and thus changing
the data but not reassigning the array as you would with ref.
That link may well be out of date, Ali's Book
(http://ddili.org/ders/d.en/index.html) is a great resource if
you are learning.
Alternately look at the std algorithm implementation of quicksort.
Nic