a problem with references

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Apr 26 04:05:57 PDT 2007


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).



More information about the Digitalmars-d mailing list