Return by 'ref' problems...

Jonathan M Davis jmdavisProg at gmx.com
Fri May 4 01:46:21 PDT 2012


On Friday, May 04, 2012 11:38:32 Manu wrote:
> 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...

That's thanks to the nonsense that putting const on the left-hand side of a 
member function is legal, making it so that you _must_ use parens with const 
and return types for the const to apply to the return type rather than the 
function.

> ref const(Thing) function() blah2 = &func;
> 
> Error: variable remedy.hud.blah2 only parameters or foreach declarations
> can be ref

Hmm. Well assuming that you can't fix the problem with parens (and I don't 
think that you can), you should probably use typeof. Either

typeof(ref const(Thing) function()) blah2 = &func;

will work (I'm not sure if it will), or if you have a function (e.g. foo) of 
type ref const(Thing) function(), then you could do

typeof(foo) blah2 = &func;

- Jonathan M Davis


More information about the Digitalmars-d mailing list