I have a base struct FMyStructBase, and a bunch of child structs FMyStructChild : public FMyStructBase. I’m iterating through a TArray, identifying which subchild each member is, and then handling each child differently.
Where I’m running into trouble is accessing data unique to the child class. As an example, say I have the following practice version:
In order to access the float, I take a member I know for a fact to belong to the correct child class, and try to cast it:
FMyBaseStruct baseVersion;
FMyChildStruct childVersion;
baseVersion = childVersion;
FMyChildStruct tempChild = Cast<FMyChildStruct>(childVersion); //Cast the object to the desired subclass
if (childVersion) { //If the cast succeeded...
return childVersion.uniqueFloat; //Access its unique members and do whatever
}
However, it really doesn’t like my cast; this returns an error at compile-time, “None of the 2 overloads could convert all the argument types”. Is it not possible to cast structs at all?
The whole idea of casting is to reinterpret the underlying bytes (and thus operate on memory addresses) through pointers as different data-types. The idea of casting doesn’t make a lot of sense otherwise.
Oh hey, great call; I had no idea that casting operated that way, that explains a lot.
Using your version verbatim produces an error, “conversion requires reinterpret_cast, C-style cast or function-style cast”, but changing it to a C-style cast compiles cleanly, thank you very much!