How to make OnComplete Anim Montage in c++?

I need to make something like this blueprint(screenshot)
2kl9yUwGWrA

I was able to find CompleteDelegate, but i need to continue executing code after the end of Anim Montage and in the delegate you have to use another function. I need to exucute this code sequentially, but i don’t understand how to make it correctly.

void AMyCharacter::PistolSlot()
{
	if (!weaponSlots[1]->IsAttachToHand) {
		UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance();
		if (AnimInstance && UnequipRifle) {

			AnimInstance->Montage_Play(UnequipRifle);
			AnimInstance->Montage_JumpToSection("UnequipRifle");

			FOnMontageEnded CompleteDelegate;
			CompleteDelegate.BindUObject(this, &AMyCharacter::FunctionToExecuteOnAnimationEnd);
			AnimInstance->Montage_SetEndDelegate(CompleteDelegate, UnequipRifle);
		}
		currentWeapon->IsAttachToHand = false;
		if (EquipPistol) {
			AnimInstance->Montage_Play(EquipPistol);
			AnimInstance->Montage_JumpToSection("EquipPistol");

			FOnMontageEnded CompleteDelegate;
			CompleteDelegate.BindUObject(this, &AMyCharacter::FunctionToExecuteOnAnimationEnd);
			AnimInstance->Montage_SetEndDelegate(CompleteDelegate, UnequipRifle);
		}
		currentWeapon = weaponSlots[1];
		currentWeapon->IsAttachToHand = true;
		playerAnimRef->SwitchWeaponType(currentWeapon->weaponType);	
	}
}