Declaring a pointer to a function returning a ref

Jean-Louis Leroy jl at leroy.nyc
Tue Jul 31 21:29:26 UTC 2018


How do I declare a variable that contains a pointer to a function 
returning a reference?

   import std.stdio;

   int foo(return ref int a)
   {
     a = 42;
     return a;
   }

   ref int bar(return ref int a)
   {
     a = 42;
     return a;
   }

   void main()
   {
     int x;
     auto apf = &foo;
     writeln(typeid(apf)); // int function(return ref int)*
     int function(return ref int) xpf = &foo;

     auto apb = &bar;
     writeln(typeid(apb)); // int function(return ref int) ref*

     // int function(return ref int) ref xpb = &bar; // Error: no 
identifier for declarator `int function(return ref int)`
     // ref int function(return ref int) xpb = &bar; // Error: 
variable `castfunc.main.xpb` only parameters or `foreach` 
declarations can be `ref`
   }



More information about the Digitalmars-d mailing list