【发布时间】:2020-06-08 04:37:57
【问题描述】:
在一个cpp文件中,我的使用:
BoxComp->OnComponentBeginOverlap.AddDynamic(this, &AAICharacter::OnBoxOverlap);
BoxComp->OnComponentEndOverlap.AddDynamic(this, &AAICharacter::OnBoxEndOverlap);
出现以下错误:
cannot convert argument 2 from 'void (_cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)' to 'void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
这是我的头文件与相关函数的样子。省略了一些代码来尝试创建我认为是最小的可重现示例;如果我因为缺乏专业知识而遗漏了任何有价值的东西,那就 lmk:
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Engine/DataTable.h"
#include "Subtitle.h"
#include "Components/BoxComponent.h"
#include "Components/AudioComponent.h"
#include "AICharacter.generated.h"
/**
* The purpose of this class is to create a dummy AI for testing out the code for character interactions.
*/
UCLASS()
class GV_PROJECT_API AAICharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AAICharacter();
private:
UFUNCTION()
void OnBoxOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex, bool bFromSweep, const FHitResult & SweepResult);
UFUNCTION()
void OnBoxEndOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex)
protected:
/*If the player is inside this box component he will be able to initiate a conversation with the pawn*/
UPROPERTY(VisibleAnywhere)
UBoxComponent* BoxComp;
有人知道这个错误吗?
【问题讨论】:
-
至于错误信息,它是相当不言自明的。当您需要类型为
void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)的东西时,作为第二个参数提供的东西是void (_cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)类型。 (如果您看不到区别,请将这两种类型放在文本编辑器中的连续行中。) -
A minimal reproducible example 将删除
AAICharacter中不需要重现错误的部分。除了OnBoxOverlap和OnBoxEndOverlap的声明之外,你还需要从那个类中获得多少? -
@JaMiT 我确实理解错误在说什么,但我不确定如何为程序提供它想要的东西。我尝试在它应该缺少的地方添加一个原始组件,但所做的只是创建了一大堆新错误。
-
至于重现错误不需要的部分,老实说我不知道。我对使用虚幻引擎的 c++ 非常非常,我担心尝试修剪某些东西可能会删除可以帮助某人解决问题的有价值的信息。不过回想起来,我想我可以安全地省略 ufunctions 和 upproperties,所以我会编辑这些部分。
-
通常不知道重现错误需要哪些部分,哪些不需要。这就是为什么标准程序是复制您的代码,并在复制中开始剥离内容。如果错误消失了,你已经剥离了太多。如果没有其他内容可以删除而不删除错误,则示例很少。
标签: c++ unreal-engine4