Delegate / Error: cannot implicitly convert expression...
user1234
user1234 at 12.de
Sat Jun 15 20:34:33 UTC 2019
On Saturday, 15 June 2019 at 17:42:04 UTC, ag0aep6g wrote:
> 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.
True if was forgetting that the context is a hidden parameter...
Maybe it depends on the calling convention too ?
More information about the Digitalmars-d-learn
mailing list