Bug or not? "Functions cannot return a function"
    Jonathan M Davis via Digitalmars-d 
    digitalmars-d at puremagic.com
       
    Wed Nov 16 17:48:51 PST 2016
    
    
  
On Thursday, November 17, 2016 01:27:45 Meta via Digitalmars-d wrote:
> auto bug(alias f)()
> {
>      return cast(typeof(f))&f;
> }
>
> void fun() {}
>
> void main()
> {
>   bug!fun(); //Error: functions cannot return a function
> }
Well, you _can't_ return a function. You could return a function pointer or
a delegate, but not a function. What would it even mean to return a
function?
Why don't you just return &f? I don't understand why you're doing the cast.
&f should give you a pointer to f, so you have a function pointer that you
can then call later (though you'd need to assign the result of bug!fun() to
a variable, since it does nothing otherwise).
-  Jonathan M Davis
    
    
More information about the Digitalmars-d
mailing list