【问题标题】:How find structure index in a structure-TArray?如何在结构 TArray 中找到结构索引?
【发布时间】:2021-10-18 11:09:09
【问题描述】:

BP 上有一个函数在数组中寻找一个空槽并填充它。当试图用 C++ 重写它时,它会抛出错误 C2678 "binary"==": an operator accepting a leftoperand of type "const FSlotStructure" was not found (or there is no appropriate conversion)" 图中的变量对应代码​​中的变量。 Find() 函数本身不会在 Array Inventory 数组中搜索 FSlotStructure 变量。什么错误?

下面的函数是自定义的,因为“FIND”和“SetArrayElem”函数来自UKismetArrayLibrary,不能直接使用。

void UInventoryComponent::CreateStack(FSlotStructure& ContentToAdd)
{
    //TArray<FSlotStructure> Inventory;

    int32 Index;

    for (auto& SlotStructure : Inventory)
    {
        int32 NewIndex = Inventory.Find(SlotStructure, Index);

        Inventory.Insert(ContentToAdd, NewIndex);
    }
}

【问题讨论】:

  • 循环看起来很奇怪。对于Inventory 中的每个项目,您都将一个项目添加到Inventory?这是故意的吗?
  • 错误似乎很明显。你正在做一个find,要找到一些东西,你需要能够匹配它。但是是不是没有为类型定义equals比较运算符,你看不出来是不是匹配,对吧?
  • 没错,因为在 BP 中一切正常,但 Inventory.Find(Slot Structure, Index) 本身也给出了错误 C2678。没错,但究竟是什么?我需要在数组中找到元素的索引并将其放入变量中。循环这样做是合乎逻辑的。但是到底应该和什么比较呢?
  • FSlotStructure是内置的,是BP生成的还是自己创建的?
  • 拥有 BP 和 c++

标签: c++ unreal-engine4 unreal-blueprint


【解决方案1】:

一切都已解决,至少代码编译没有错误。我所要做的就是将它添加到 FSlotStructure

operator bool() const
{

return true;

}

【讨论】:

    猜你喜欢
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 2016-11-25
    • 2020-03-09
    相关资源
    最近更新 更多