Using inout in delegates

Jesse Phillips jessekphillips+D at gmail.com
Thu Oct 4 07:09:12 PDT 2012


On Thursday, 4 October 2012 at 13:55:39 UTC, Jacob Carlborg wrote:
> void foo (inout int[] arr)
> {
>     auto a = { auto b = arr[0]; };
> }
>
> void main ()
> {
>     auto a = [3, 4, 5];
>     foo(a);
> }
>
> Compiling the above code with DMD 2.060 results in the 
> following error message:
>
> Error: variable main.foo.__lambda1.b inout variables can only 
> be declared inside inout functions
> Failed: /Users/jacob/.dvm/bin/dvm-current-dc  -v -o- 
> '/Users/jacob/development/d/main.d' 
> -I'/Users/jacob/development/d'
> >/Users/jacob/development/d/main.d.deps
>
> Is this a bug, a limitation of inout/delegate or am I doing 
> something else wrong?

IIRC, inout must be applied to the return type too, and it only 
works in templates.


More information about the Digitalmars-d-learn mailing list