www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - a problem with references

reply Niovol <niovol gmail.com> writes:
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
--------
Apr 26 2007
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
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).
Apr 26 2007