Problems with function as parameter

Mike Parker aldacron at gmail.com
Fri Sep 22 03:26:36 UTC 2017


On Friday, 22 September 2017 at 02:22:46 UTC, Josh wrote:

>
> src\mixer.d(80,22): Error: function pointer Mix_ChannelFinished 
> (extern (C) void function(int channel)) is not callable using 
> argument types (extern (C) void delegate(int channel))
>
> Code:
> void unmuteAfterPlaySound()
> {
> 	Mix_ChannelFinished(&channelDone);
> }
>
> extern (C) void channelDone(int channel)
> {
> 	unmuteMusic();
> }

The error message indicates that `channelDone` is a member of a 
class or a struct. A pointer to a member function is a delegate 
(or closure), not a function pointer. Free functions, static 
nested functions, and static member functions all produce 
function pointer. Non-static member functions and non-static 
nested functions all produce delegates/closures. See the docs:

https://dlang.org/spec/function.html#closures

If you need to manipulate instance members from a C callback, 
you'll need a way to implement a mechanism to work out which 
instance you need.



More information about the Digitalmars-d-learn mailing list