Ref function pointers?
Steven Schveighoffer
schveiguy at yahoo.com
Fri Jan 7 06:28:43 PST 2011
On Thu, 06 Jan 2011 22:37:07 -0500, Sean Eskapp <eatingstaples at gmail.com>
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.
-Steve
More information about the Digitalmars-d
mailing list