Problems with function as parameter

Josh moonburntm at gmail.com
Thu Sep 21 20:21:58 UTC 2017


I'm trying to write a callback function for SDL_mixer through 
Derelict, but this is the first time I've tried to use a function 
as a parameter, and so I think I'm just making a minor mistake 
somewhere.

The C SDL docs say:
****************************************************
// make a channelDone function
void channelDone(int channel)
{
     printf("channel %d finished playing.\n", channel);
}
...
// set the callback for when a channel stops playing
Mix_ChannelFinished(channelDone);
****************************************************

And my D code is:
****************************************************
void unmuteAfterPlaySound()
{
	Mix_ChannelFinished(channelDone);
}

void channelDone(int channel)
{
	unmuteMusic();
}
****************************************************

But DMD seems to be trying to run channelDone() i.e. with no 
parameters and parentheses omitted, and is giving this error:

Error: function Mixer.channelDone (int channel) is not callable 
using argument types ()
Error: function pointer Mix_ChannelFinished (extern (C) void 
function(int channel)) is not callable using argument types 
(_error_)

Is anyone able to see what I've done wrong? Any help would be 
appreciated, thanks.


More information about the Digitalmars-d-learn mailing list