【问题标题】:Unreal Engine 4.19 C++ Undeclared Identifier error, but it code IS declaredUnreal Engine 4.19 C++ Undeclared Identifier 错误,但它的代码已声明
【发布时间】:2015-11-07 15:49:12
【问题描述】:

这也发布到了 Unreal 的 AnswerHub,但它们的响应速度很慢,我想知道这是 Unreal Engine 错误还是 Visual Studio 2013/C++ 一般错误。我想如果这是一个一般错误,那么 StackOverflow 会指出它。

基本上无缘无故,Visual Studio 开始在正确检测代码时遇到问题,说空函数内有未知符号,然后它开始说已经工作的代码中有未声明的标识符,或者“->”是未知的,等等. 一个不同的文件给了我这些错误http://i.imgur.com/AVrbdTS.png?1 下面是我用来显示我的问题的代码。当我再次尝试时,它说它无法打开 ToggleForBP.generated.h

这是 Visual Studio 2013 还是虚幻引擎的错误?

我的 .h // 在项目设置的描述页面填写您的版权声明。

#pragma once

#include "GameFramework/Actor.h"
#include "ToggleForBP.generated.h"

UCLASS()
class PLAYGROUND_API AToggleForBP : public AActor
{
    GENERATED_BODY()

public: 
    // Sets default values for this actor's properties
    AToggleForBP();

    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

    // Called every frame
    virtual void Tick(float DeltaSeconds) override;


    //Toggles between on and off
    void SwitchOnOff();

    bool UniqueValueBlah;


};

我的 .cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "Playground.h"
#include "ToggleForBP.h"


// Sets default values
AToggleForBP::AToggleForBP()
{
    // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

}

void SwitchOnOff()
{

    UniqueValueBlah = true;
}

// Called when the game starts or when spawned
void AToggleForBP::BeginPlay()
{
    Super::BeginPlay();

}

// Called every frame
void AToggleForBP::Tick( float DeltaTime )
{
    Super::Tick( DeltaTime );

}

我从上面的代码中得到的错误:

Error   2   error : Failed to produce item: D:\Unreal Projects\Playground\Binaries\Win64\UE4Editor-Playground-3827.dll  D:\Unreal Projects\Playground\Intermediate\ProjectFiles\ERROR   Playground
Error   1   error C2065: 'UniqueValueBlah' : undeclared identifier  D:\Unreal Projects\Playground\Source\Playground\ToggleForBP.cpp 18  1   Playground
Error   3   error MSB3073: The command ""D:\Programs\Epic Games\Epic Games\4.9\Engine\Build\BatchFiles\Build.bat" PlaygroundEditor Win64 Development "D:\Unreal Projects\Playground\Playground.uproject" -rocket -waitmutex" exited with code -1.   C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets   38  5   Playground
    4   IntelliSense: identifier "UniqueValueBlah" is undefined d:\Unreal Projects\Playground\Source\Playground\ToggleForBP.cpp 18  2   Playground

【问题讨论】:

    标签: c++ unreal-engine4 undeclared-identifier


    【解决方案1】:

    将函数的签名更改为:

    void AToggleForBP::SwitchOnOff()
    {
    
        UniqueValueBlah = true;
    }
    

    不让它成为成员函数,编译器就认为它是一个全局函数。

    【讨论】:

    • ...因此它试图找到一个全局 UniqueValueBlah 标识符,但无法生成 'UniqueValueBlah' : undeclared identifier 消息。
    • 非常感谢你们两个。如果我不想输入 AToggleForBP:: ,是否应该将它放在 .h 文件中的私有下?
    • 函数声明了一个类的头文件,无论它们是私有的、受保护的还是公共的,都不需要类前缀。
    猜你喜欢
    • 1970-01-01
    • 2013-02-14
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    相关资源
    最近更新 更多