Return by 'ref' problems...

Manu turkeyman at gmail.com
Fri May 4 01:38:32 PDT 2012


So here's some problems.

I use 'const ref' to pass structs to functions (note: because 'in ref'
doesn't seem to work)
And I often need to return structs by ref too, but I'm having problems:

void test( const ref Thing x ) {} // this works fine. note, 'const ref'
works fine here (in lieu of 'in ref')


struct Thing { }
Thing thing;

const ref Thing func() { return gThing; }

This syntax complains, but it's precisely the same expression I use to pass
an argument in to a function, and it's fine there:
  remedy\modules\hud.d(35):Error: function remedy.hud.func without 'this'
cannot be const/immutable

const ref Thing function() blah = &func;

I need to take a pointer to this function, but It complains when I declare
a 'function' of this type:
  remedy\modules\hud.d(36):Error: variable remedy.hud.blah only parameters
or foreach declarations can be ref   (... what? it works for parameters?)


I try rearranging the syntax to make the first issue stop complaining:

ref const(Thing) func2() { return gThing; } // this seems to work now, but
i don't like the inconsistency...
ref const(Thing) function() blah2 = &func;

Error: variable remedy.hud.blah2 only parameters or foreach declarations
can be ref
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120504/4e2a58fa/attachment.html>


More information about the Digitalmars-d mailing list