[英]How to fix "Pointer to Incomplete class type is not allowed" error in Unreal Engine 4
I'm trying to learn C++ using a book called "Learning C++ by Creating Games with Unreal Engine 4" by Sharan Volin.我正在尝试使用 Sharan Volin 的一本名为“通过使用虚幻引擎 4 创建游戏来学习 C++”的书来学习 C++。 Up to this point, I had been following the examples, but I got stuck at this error, despite the fact that I'm typing everything verbatim from the text.到目前为止,我一直在关注这些例子,但我被这个错误困住了,尽管我正在逐字输入文本中的所有内容。 Is there something I am missing or not understanding?有什么我遗漏或不理解的吗?
I've tried to see if there were any other guides or Git Repos on this exercise, but had no luck.我试图看看这个练习是否有任何其他指南或 Git Repos,但没有运气。 Other Stack user questions regarding error code E0393 (the error I'm getting) don't seem to help, as I have the Avatar.h
file included in the Avatar.cpp
file.关于错误代码 E0393(我得到的错误)的其他 Stack 用户问题似乎没有帮助,因为Avatar.h
文件中包含Avatar.cpp
文件。
This is the code in the segment in the Avatar.cpp
file giving me an error, specifically the last two lines that start as PlayerInputComponent->
这是Avatar.cpp
文件中段中的Avatar.cpp
给我一个错误,特别是最后两行以PlayerInputComponent->
开头
// Called to bind functionality to input
void AAvatar::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
check(PlayerInputComponent);
PlayerInputComponent->BindAxis("Forward", this, &AAvatar::MoveForward);
PlayerInputComponent->BindAxis("Strafe", this, &AAvatar::MoveRight);
}
This is some of the code present in the Avatar.h
file, with only the last 4 lines being what I was instructed to type in.这是Avatar.h
文件中的一些代码,只有最后 4 行是我被指示输入的内容。
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
//New! These 2 new member function declarations
//they will be used to move our player around!
void MoveForward(float amount);
void MoveRight(float amount);
};
The final result should allow me to move an avatar in the Unreal Project forward and to the right upon pressing "W" and "D" respectively.最终结果应该允许我在分别按下“W”和“D”后将虚幻项目中的化身向前和向右移动。 However, in the Avatar.cpp
file, I get the error E0393 pointer to incomplete class type is not allowed
.但是,在Avatar.cpp
文件中,我收到错误E0393 pointer to incomplete class type is not allowed
。 I also never get the project to launch in the Unreal Editor.我也从未让项目在虚幻编辑器中启动。
只需转到头文件“Avatar.h”并键入#include“Components/InputComponent.h”
In your cpp file as you have forward declared the class.在您的 cpp 文件中,您已经向前声明了该类。 You need to have the include for the actual definition in the .cpp file.您需要在 .cpp 文件中包含实际定义的包含。 So you need to have the include for the UInputComponent.所以你需要包含 UInputComponent。
On the docs for the Component: here you will see at the bottom of the page it's location in the engines files.在组件的文档上: 在这里您将在页面底部看到它在引擎文件中的位置。
#include "Runtime/Engine/Classes/Components/InputComponent.h"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.