Steven Schveighoffer <[email protected]> wrote:
On Thu, 06 Jan 2011 22:37:07 -0500, Sean Eskapp
<[email protected]> wrote:
Is there a way to create a function pointer which returns a reference?
In all
the ways I've tried it, my return value becomes "not an lvalue".
int x;
ref int foo()
{
return x;
}
void main()
{
auto func = &foo;
pragma(msg, typeof(func).stringof);
func() = 5;
}
compiles and outputs during compilation:
int function() ref
However, doing this:
int function() ref func = &foo;
results in an error:
testreffuncptr.d(9): no identifier for declarator int function()
testreffuncptr.d(9): semicolon expected, not 'ref'
testreffuncptr.d(9): found 'ref' instead of statement
So, yes, you can make one. No you can't specifically type it ;) You
must use auto. I find the type string extremely strange too.
I think this is bugzilla-worthy.
It's a known problem, not sure if it is in Bugzilla though.
Workaround:
alias ref int function() rifn;
rifn fn = &foo;
--
Simen