April 26, 2007 a problem with references | ||||
|---|---|---|---|---|
| ||||
How can I use references?
I found an example:
line 1| //
line 2| void def(ref int x)
line 3| {
line 4| x += 1;
line 5| }
But this example doesn't work on my computer. The errors appear:
-----------------------
C:\Work\NeuroV.d\main.d(3): found 'int' when expecting ')'
C:\Work\NeuroV.d\main.d(3): semicolon expected following function
declaration
C:\Work\NeuroV.d\main.d(3): no identifier for declarator x
C:\Work\NeuroV.d\main.d(3): semicolon expected, not ')'
C:\Work\NeuroV.d\main.d(3): Declaration expected, not ')'
C:\Work\NeuroV.d\main.d(5): unrecognized declaration
--------
| ||||
April 26, 2007 Re: a problem with references | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Niovol | Niovol wrote:
> How can I use references?
> I found an example:
> line 1| //
> line 2| void def(ref int x)
> line 3| {
> line 4| x += 1;
> line 5| }
>
> But this example doesn't work on my computer. The errors appear:
> -----------------------
> C:\Work\NeuroV.d\main.d(3): found 'int' when expecting ')'
> C:\Work\NeuroV.d\main.d(3): semicolon expected following function
> declaration
> C:\Work\NeuroV.d\main.d(3): no identifier for declarator x
> C:\Work\NeuroV.d\main.d(3): semicolon expected, not ')'
> C:\Work\NeuroV.d\main.d(3): Declaration expected, not ')'
> C:\Work\NeuroV.d\main.d(5): unrecognized declaration
> --------
What compiler version are you using?
The "ref" keyword was introduced in DMD v1.011, so it won't work in any DMD version before that (nor any GDC version currently released).
So if you're using an older version (or GDC) either upgrade or use "inout" instead (that's what it was called before v1.011, and it still works).
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply