If this question has been asked, I apologize.
I thought you couldn't bind functions with a different signature, but look at this:
void TakesChar(char parameter)
{
std::cout << parameter << std::endl;
}
using CallSig = void(float);
using CallBack = std::function<CallSig>;
int main()
{
CallBack callback = std::bind(&TakesChar, std::placeholders::_1);
callback(1.1f);
callback(2.2f);
return 0;
}
That compiles and runs. You can try different parameter types and numbers. You can, for instance, modify TakesChar
so that it takes no parameters, and it will still compile.
Why is this? Is there a rationale behind it? And can I enforce signatures to match exactly?
Thanks.