【问题标题】:Unreal Engine 4.16, C++ Include header files虚幻引擎 4.16,C++ 包含头文件
【发布时间】:2017-11-17 08:04:58
【问题描述】:

我正在使用 Unreal Engine 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”没有错

【问题讨论】:

标签: c++ header-files unreal-engine4


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我在使用 Unreal Engine 16.1 和 Visual Studio 2017 时遇到了相同的错误。虽然我不完全确定是什么原因造成的,但解决方案是将导入移动到 .cpp 文件中,而不是头文件(.h)。

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

    【讨论】:

      猜你喜欢
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-03
      • 2018-09-01
      • 1970-01-01
      • 2015-10-12
      • 2020-09-14
      相关资源
      最近更新 更多