虚幻引擎4.16,C++包含头文件

Unreal Engine 4.16, C++ Include header files

本文关键字:C++ 包含头 文件 引擎      更新时间:2023-10-16

我正在使用虚幻引擎4.16和Visual Studio 2017,我正在尝试导入一个类:"PhysicsEngine/PhysicsHandleComponent.h",我得到了很多错误。

如果我不导入它,一切正常,构建正常,一切正常,所以问题被隔离了。

在头文件 Grabber.h 中,在包含之前,我有这个:

#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Grabber.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UGrabber : public UActorComponent
{
    GENERATED_BODY()
    ...

一切都正常。

但是一旦我包含正确的标题,就像这样:

#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PhysicsEngine/PhysicsHandleComponent.h"
#include "Grabber.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UGrabber : public UActorComponent
{
    GENERATED_BODY()
    ...

"UCLASS"(第 10 行(和"class"(第 11 行(带有下划线,不会构建任何内容,并且会抛出以下错误:

E0077   this declaration has no storage class or type specifier ...Grabber.h   10
E0065   expected a ';'  ...Grabber.h   11

为什么不让我导入此文件?

编辑:这是正确的文件,正确的拼写,它是引擎中的文件。它不是我写的,所以"PhysicsEngine/PhysicsHandleComponent"没有错

我遇到了同样的问题,我发现如果您将生成的.h文件移动到另一行(通过在其上方按回车键(,则会出现错误。尝试使用现有 #includes 上方的空白行之一。(如果需要,您可以移动 #pragma 一次(

我在虚幻引擎16.1和Visual Studio 2017的不同标题上遇到了相同的错误。虽然我不完全确定是什么原因造成的,但解决方案是简单地将导入移动到.cpp文件中,而不是头 (.h( 文件中。

我相信这与虚幻生成的预编译标头有关,一旦我们尝试包含不同的标头,Visual Studio 可能无法再正确看到它们。