【问题标题】:What does it mean to "Implement an empty logic" for a function in ue4?ue4中的函数“实现一个空逻辑”是什么意思?
【发布时间】:2020-06-09 22:20:42
【问题描述】:

我正在关注设置角色交互的教程,其中一部分说使用以下代码制作头文件:

public:

/*This property will be used in order to bind our subtitles
Binding will make sure to notify the UI if the content of the following
variable change.*/
UPROPERTY(BlueprintReadOnly)
FString SubtitleToDisplay;


/*Updates the displayed subtitles based on the given array*/
UFUNCTION(BlueprintCallable, Category = DialogSystem)
void UpdateSubtitles(TArray<FSubtitle> Subtitles);

/*This array will populate our buttons from within the show function*/
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
TArray<FString> Questions;

/*Adds the widget to our viewport and populates the buttons with the given questions*/
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = DialogSystem)
void Show();

然后,它告诉我“现在为 UpdateSubtitles 函数实现一个空逻辑。”我不知道这意味着什么,并且考虑到 UpdateSubtitles 是在我编译此代码时给我一个错误的一件事,这可能很重要。有谁知道这个术语指的是什么?

【问题讨论】:

  • 这不是一个常见的短语。我的猜测是他们的意思是实现(创建定义)函数,并将主体留空。另外,我真的建议买一本 C++ 书,有一个很好的列表 here。虚幻 C++ 并不完全相同,但 C++ 知识是一种很好的可转移技能(尤其是对于游戏而言)。它还可以消除学习虚幻的心痛,并更全面地了解在虚幻中解决问题的方法。

标签: c++ logic unreal-engine4


【解决方案1】:

意思就是把函数的内容留空或者返回一个空的结果如:

FString AMyCharacter::GetNickname()
{
    return "";
}

在返回类型不为 void 的情况下。

【讨论】:

  • 明白了。那么在这种情况下我将如何解决这个问题呢?我的 cpp 文件除了 DialogUI 的包含(这个类的名称)之外是空白的,而且我对 c++ 很陌生,所以不知道如何为这个函数创建一个定义。
  • 在此示例中,您必须添加“void ClassName::UpdateSubtitles(TArray Subtitles){}”并对 Show() 执行相同操作,因为如果您不这样做也会引发错误.
【解决方案2】:

感谢您的评论,我明白了!不过和你描述的有点不一样,其实是:

void UDialogUI::UpdateSubtitles(TArray<FSubtitle> Subtitles) {}

只有这一行;按照建议添加 Show() 的定义实际上会引发错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多