Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OnComponentBeginOverlap.AddDynamic是否表示函数模板的实例与参数列表不匹配?_C++_Unreal Engine4 - Fatal编程技术网

C++ OnComponentBeginOverlap.AddDynamic是否表示函数模板的实例与参数列表不匹配?

C++ OnComponentBeginOverlap.AddDynamic是否表示函数模板的实例与参数列表不匹配?,c++,unreal-engine4,C++,Unreal Engine4,在cpp文件中,我使用: BoxComp->OnComponentBeginOverlap.AddDynamic(this, &AAICharacter::OnBoxOverlap); BoxComp->OnComponentEndOverlap.AddDynamic(this, &AAICharacter::OnBoxEndOverlap); 获取了以下错误: 无法将参数2从“void(\u cdecl AAICharacter::*)(AActor*,UPrim

在cpp文件中,我使用:

BoxComp->OnComponentBeginOverlap.AddDynamic(this, &AAICharacter::OnBoxOverlap);
BoxComp->OnComponentEndOverlap.AddDynamic(this, &AAICharacter::OnBoxEndOverlap);
获取了以下错误:

无法将参数2从“void(\u cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult&)”转换为“void(\u cdecl AAICharacter::*)(UPrimitiveComponent*,AActor*,UPrimitiveComponent*,int32,bool,const FHitResult&)

下面是我的头文件和相关函数的样子。一些代码被省略,以尝试创建我认为是最小可复制的示例;如果我因缺乏专业知识而遗漏了任何有价值的内容,请立即:

#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;

有人熟悉这个错误吗?

这个错误是不言自明的

无法将参数2从“void(\u cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult&)”转换为“void(\u cdecl AAICharacter::*)(UPrimitiveComponent*,AActor*,UPrimitiveComponent*,int32,bool,const FHitResult&)

指示行中的第二个参数(因此
&AAICharacter::OnBoxOverlap
&AAICharacter::OnBoxEndOverlap
)在消息中列出了第一种类型,而被调用的函数(
AddDynamic()
)需要第二种类型。有时不同的类型不是问题,但在这种情况下,无法从一种类型转换为另一种类型

我看到的唯一诀窍是在比较了所讨论的类型之后。它有助于插入空格,以便更好地排列

 void (_cdecl AAICharacter::*)(                      AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
 void (_cdecl AAICharacter::*)(UPrimitiveComponent*, AActor*,UPrimitiveComponent*,int32,bool,const FHitResult &)
两个成员函数使用的参数比预期的少。如果这是使用这些函数的唯一位置,则可以直接向它们添加附加的
UPrimitiveComponent*
参数。否则,您可能希望引入具有所需签名的包装函数,忽略它们的第一个参数,并调用该方法(一个包装将调用
OnBoxOverlap()
,而另一个将调用
OnBoxEndOverlap()
)。例如:

UFUNCTION()
void OnBoxOverlapWrapper(UPrimitiveComponent* /*ignored*/, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherIndex, bool bFromSweep, const FHitResult & SweepResult)
{
    OnBoxOverlap(OtherActor, OtherComp, OtherIndex, bFromSweep, SweepResult);
}

这附带了一个警告:您知道您忽略的参数的重要性吗?您的代码可能包含一个当前未被注意到的错误,该错误源于未使用第一个参数。

至于错误消息,它是不言自明的。当您需要类型为
void(\u cdecl AAICharacter::*)(AActor*,UPrimitiveComponent*,int32,bool,const FHitResult&)的对象时,您作为第二个参数提供的对象是类型为
void(\u cdecl AAICharacter::*)(UPrimitiveComponent*,AActor*,UPrimitiveComponent*,int32,bool,const FHitResult&
的对象。(如果看不到差异,请将这两种类型放在文本编辑器中的连续行中。)a将删除
AAICharacter
中不需要重现错误的部分。除了
OnBoxOverlap
OnBoxEndOverlap
的声明之外,您还需要从该类中获得多少?@JaMiT我确实理解错误的意思,但我不确定如何满足程序的要求。我试着添加一个基本组件,但它应该缺少一个,但所做的只是创建了一系列新的错误。至于不需要重现错误的部分,我真的没有任何线索。我对C++的新引擎非常陌生,我担心尝试修剪某些东西会潜在地去除有助于解决问题的有价值的信息。但是回顾过去,我想我本可以安全地省略uffunction和upperty,所以我将编辑掉这些部分。通常不知道哪些部分是重现错误所必需的,哪些部分不是。这就是为什么一个标准的过程是复制你的代码,并在副本中开始剥离东西。如果错误消失,则说明您已删除了太多内容。如果在不删除错误的情况下无法删除任何其他内容,则示例非常简单。此解决方案与OnBoxEndOverlap函数配合使用效果很好,但OnBoxOverlap函数的版本在以下行中出现错误,称为“缺少变量名:
uffunction()void OnBoxOverlap Wrapper”(UPrimitiveComponent*/*忽略*/,AActor*其他参与者,UPrimitiveComponent*其他Comp,int32 OtherIndex,bool bFromSweep,const fHirtResult&SweepResult)
@DualBall没有足够的信息来了解发生了什么。另外,它看起来像是一个新问题。明白了;我会在其他地方问我的新问题。谢谢你的帮助!