I cannot pass a lambda to function
I tried TFunction& TFunctionRef but am getting the same error
void MyFunction(TFunctionRef<void(const float, const TArray<int32>&, Args&...)> func ){}
object.MyFunction([](const float dt,
const TArray<int32>& obects,
Position* p,
Velocity* v){/*...*/});
Chatouille
(Chatouille)
2
Hmm what is Args
in your function declaration ?
MyFunction must either be a template, or be located in a template struct/class like this
template<typename... Args>
Even then, the compiler doesn’t seem able to automatically infer the extra types so you’ll have to supply them :
template<typename... Types>
void MyFunction(TFunction<void(const float, const TArray<int32>&, Types&...)> func) {}
MyFunction<Position*, Velocity*>([](const float dt, const TArray<int32>& arr, Position* p, Velocity* v) {
//...
});
its variadic params in template class as you said
the types are supplied with the class initialization
template<typename... Args>
class MyClass{}
-------------------------
MyClass<Position,Velocity > object;
error C2664: 'void MyClass<Position,Velocity>::MyFunction(TFunction<void (float,const TArray<int32,FDefaultAllocator> &,Position &,Velocity &)>)': cannot convert argument 1 from 'AMyTestActor::BeginPlay::<lambda_fb06ae8b1ad5bbcb3d63bfe33c0b0665>' to 'TFunction<void (float,const TArray<int32,FDefaultAllocator> &,Position &,Velocity &)>'