Return by 'ref' problems...

Manu turkeyman at gmail.com
Fri May 4 03:03:37 PDT 2012


On 4 May 2012 11:46, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> 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 = &func2;
>

This fails quite spectacularly:
  remedy\modules\hud.d(33):expression expected, not 'ref'
  remedy\modules\hud.d(33):found 'const' when expecting ')'
  remedy\modules\hud.d(33):function declaration without return type. (Note
that constructors are always named 'this')
  remedy\modules\hud.d(33):no identifier for declarator typeof(0)(Thing)
  remedy\modules\hud.d(33):semicolon expected following function declaration
  remedy\modules\hud.d(33):Declaration expected, not 'function'



> 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 = &foo;
>

This also fails:
  Error: variable remedy.hud.blah2 cannot be declared to be a function

>_<
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120504/c6ae0e8e/attachment-0001.html>


More information about the Digitalmars-d mailing list