error C2664 : void cannot convert argument 3 from 'void' to 'void (__cdecl::AGun* ) (void)'

Full Error:
error C2664: ‘void FTimerManager::SetTimer<AGun>(FTimerHandle &, UserClass*, (__cdecl::AGun* )(void) , float, bool, float)’ : void cannot convert argument 3 from ‘void’ to ‘void (__cdecl::AGun* ) (void)’

I’ve got this problem when this line of code was compiling.

GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, PullTrigger(), ShootDelay, false);

I don’t know why but there is problem with PullTrigger() function.
Here’s declaration of it in header file:

virtual void PullTrigger();

Please help me.

GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &AGun::PullTrigger, ShootDelay, false);

Highly suggest searching the code base for things like this, you’ll find a ton of examples. If you don’t have the Engine source, get it.

Just to further clarify on what Matt said, the reason it’s not compiling is that the parameter wants a function pointer. With the way you wrote it, it’s instead going to call PullTrigger and pass the return value of that function (I’m assuming its return type is void) as the parameter. To pass a function pointer, you instead do what Matt wrote, which is ampersand and the class scoped function name without parentheses i.e. &AGun::PullTrigger.

1 Like

Thank you for help