array of functions/delegates

Mike Parker aldacron at gmail.com
Tue Dec 24 16:36:53 UTC 2019


On Tuesday, 24 December 2019 at 13:13:12 UTC, MoonlightSentinel 
wrote:
> On Tuesday, 24 December 2019 at 10:40:16 UTC, Mike Parker wrote:
>> struct S {}
>> void f1(S s) {}
>> void f2(S s) {}
>>
>> alias Func = immutable(void function());
>>
>> immutable Func[2] funcs = [cast(Func)&f1, cast(Func)&f2];
>>
>> Though, it's not clear to me wy the one requires casting the 
>> pointer type and the other doesn't.
>
> Because typeof(&f1) == void function(S)

Right. I didn't modify the alias declaration when I took the 
functions out of the struct. I saw the immutable in the error 
message and thought that was the problem.

alias Func = void function(S);


More information about the Digitalmars-d-learn mailing list