pdenton
(Leszek Górniak)
November 21, 2020, 6:08pm
1
Hello,
How to define a function parameter, so I can pass another function with it?
I’m trying to create a function template that will take another function (but not UFUNCTION) as parameter, like in BindUObject:
Delegate.BindUObject(this, &AMyTestActor::MyTestFunction);
I tried to simply recreate the way it’s done in BindUObject:
template <typename UserClass, typename... VarTypes>
inline void BindUObject(UserClass* InUserObject, typename TMemFunPtrType<false, UserClass, RetValType (ParamTypes..., VarTypes...)>::Type InFunc, VarTypes... Vars)
but this gives me “no instance of overloaded function matches the argument list” compile error when I try to pass another function in my function.
Kehel18
(Kehel18)
November 23, 2020, 5:23pm
2
Hi! There are several things that can help you
1 Like
pdenton
(Leszek Górniak)
November 25, 2020, 3:39pm
3
OK, I managed to do this like that:
template <typename UserClass, typename... VarTypes>
static void MyFunction(UserClass* WorldContextObject, typename TMemFunPtrType<false, UserClass, void(VarTypes...)>::Type InFunc, VarTypes... Vars)
{
FDelegate MyDelegate;
MyDelegate.BindUObject(WorldContextObject, InFunc, Vars...);
//...
}
The only restriction is the parameter function InFunc must have return type void (or other predefined type), but void is enough for me.
pdenton
(Leszek Górniak)
November 25, 2020, 3:41pm
4
Thanks, I ended up using TMemFunPtrType.