简体   繁体   English

返回 const 指针会在虚幻引擎中引发编译错误?

[英]Returning a const pointer throws a compile error in Unreal Engine?

I am not terribly great at C++ so I am sorry in advance if this is just a silly mistake.我在 C++ 方面并不是非常出色,所以如果这只是一个愚蠢的错误,我提前道歉。 I was trying to expose the XMLParser to blueprints in Unreal Engine我试图将 XMLParser 暴露给虚幻引擎中的蓝图

Using VS, the code doesn't show any compile errors inline.使用 VS,代码不会显示任何内联编译错误。 (ie no red lines anywhere) However, when I try to compile, I get the following error: (即任何地方都没有红线)但是,当我尝试编译时,出现以下错误:

Unrecognized type 'FXmlNode' - type must be a UCLASS, USTRUCT or UENUM

The line of code in question:有问题的代码行:

UFUNCTION(BlueprintCallable)
        const FXmlNode* GetRoot();

I updated the Build.cs with the XMLParser module and can access the functions inside of the various XML classes.我使用 XMLParser 模块更新了 Build.cs,并且可以访问各种 XML 类中的函数。 However, I find it odd that the compiler doesn't recognize it.但是,我觉得编译器无法识别它很奇怪。 Does anyone know what might be causing this?有谁知道这可能是什么原因造成的?

Any help would be greatly appreciated.任何帮助将不胜感激。

The solution to this was rather a simple once I actually thought about it a little bit.一旦我真正考虑了一下,解决这个问题就相当简单了。 The XmlNode class was not a UCLASS type and I can't return a non-U* type inside of Blueprints which was an issue. XmlNode class 不是 UCLASS 类型,我无法在蓝图中返回非 U* 类型,这是一个问题。 (Hence why the error makes sense now) (因此为什么这个错误现在有意义)

Instead I created another wrapper class for the XmlNode class itself and made it a UCLASS type.相反,我为 XmlNode class 本身创建了另一个包装器 class 并使其成为 UCLASS 类型。 From there it was rather easy to wrap the XmlNode class since it mainly was returning Strings and other node references.从那里包装 XmlNode class 相当容易,因为它主要返回字符串和其他节点引用。

Reflection system in UE4 does not support pointers to USTRUCTS. UE4 中的反射系统不支持指向 USTRUCTS 的指针。 You can use it in your code, but it's not possible to expose USTRUCT pointers to Blueprints, you must return struct either by value or const reference您可以在代码中使用它,但不能将 USTRUCT 指针暴露给蓝图,您必须通过值或 const 引用返回 struct

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM