<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 10, 2020 at 11:55 AM Max Samukha via Digitalmars-d-learn <<a href="mailto:digitalmars-d-learn@puremagic.com">digitalmars-d-learn@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We can get the compile time equivalent of a member function's <br>
address by applying '&' to the function in a static context:<br>
<br>
struct S {<br>
     void foo() {}<br>
}<br>
<br>
enum pfoo = &S.foo; // ok<br>
<br>
void main() {<br>
     // now we can use the pointer to create, for example, a <br>
delegate<br>
     S s;<br>
     void delegate() dg;<br>
     dg.ptr = &s;<br>
     dg.funcptr = pfoo;<br>
     dg();<br>
}<br>
<br>
However, we can't do that to a nested function:<br>
<br>
void main() {<br>
     void foo() {<br>
     }<br>
     enum pfoo = &foo; // weird kind of an enum delegate; <br>
pfoo.funcptr can't be accessed at compile time.<br>
}<br>
<br>
Is there a way to get a pointer to a non-static nested function?<br></blockquote><div><br></div><div>non static nested function is a delegate, so you can just assign it to delegate like I have posted or you can du this:</div><div><br></div>import std.stdio;<br>void main() {<br>    void foo() {<br>        writeln("It works as expected");<br>    }<br>    enum pfoo = &foo;<br>        <br>    void delegate() dg;<br>    dg.ptr = pfoo.ptr;<br>    dg.funcptr = pfoo.funcptr;<br>    dg();    <br><div>} </div></div></div>