Delegate / Error: cannot implicitly convert expression...

ag0aep6g anonymous at example.com
Sat Jun 15 17:42:04 UTC 2019


On Saturday, 15 June 2019 at 17:24:45 UTC, user1234 wrote:
> ---
> void foo(){writeln(__PRETTY_FUNCTION__);}
>
> void main(string[] args)
> {
>     void delegate() dg;
>     dg.funcptr = &foo;
>     dg.ptr = null; // usually a "this" or a frame address
>     dg();
> }
> ---
>
> because dg.ptr would be used to retrieve the offset of the 
> locals variable used in the parent stack or the address of a 
> class instance (the this). But this is not required at all 
> here. The opposite way would lead to various access violation.

That only works because foo doesn't have any parameters. When you 
add even just one, things will go wrong.


More information about the Digitalmars-d-learn mailing list