Forward Declaration for Structure
I can easily use forward declarations on classes, but the same mechanism does not work on structures. Let's say that in a single header file, I wrote this:
When I compile it, the compiler always fail with the following message: "Unrecognized type 'FStructB' - type must be a UCLASS, USTRUCT or UENUM". This sort of error does not happen in ordinary C++. Is this a bug in UE or did I do something wrong?
asked Aug 14 '16 at 08:56 AM in C++ Programming
To expand a bit on what Shohei is saying. This is how structs work in UE4.
The absolute minimum you need is:
This includes having "F" before the name of the struct, or you will get a compiling error of, "Struct 'TestingStructA' has an invalid Unreal prefix, expecting 'FestingStructA'".
You need GENERATED_BODY( ), or you will get the compiling error of, "Expected a GENERATED_BODY() at the start of struct".
Thank you for submitting a bug report, however at this time we believe that the issue you are describing is not actually a bug with the Unreal Engine, and so we are not able to take any further action on this. If you still believe this may be a bug, please provide steps for us to reproduce the issue, and we will continue our investigation.
You cannot forward declare a class or struct if you don't use it as a pointer. Pointers have fixed sizes so the compiler can allocate enough space for it. Non-pointers, on the other hand, are variable sizes and the compiler doesn't know how much memory to allocate at compile time.
Your illegal line is line 10 where you have attempted to use an incomplete class type. Change the variable to a pointer. If you do not change it to a pointer you will not be able to compile two structs that have a strong dependence on each other.
answered Aug 14 '16 at 05:41 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here