How do I pass pointer to function as parameter?

I have declared a delegate inside my function, and to bind it easier, I just want user to pass a pointer to function, like

gameEvent.AddEvent(this,UBasicExample::SimpleEvent)

And inside, bind SimpleEvent to dispatcher. How should AddEvent look like?

Normally in C++ pointer type is declered this way

ReturnType (*NameOfPointerVarable)(ArgType, ArgType);

UE4 has special template class providing better support and it’s the one delegates are using

TFunction<ReturnType(ArgType, ArgType)> NameOfPointerVarable;

If you function type don’t have any return then you put void same as you do in function declarations, if you have no arguments you simply leave empty ()

Note that you can bind delegate to delegate. Delegate works like storage function bindings and you can pass then one to another. It also let you bind functions with extra arguments. I see this more rethen then use function pointers to forward it

1 Like