Why does casting a struct cause an error?
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:
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?
asked Dec 23 '15 at 04:04 AM in C++ Programming
Just gonna go out on a limb and say, because it isn't a pointer? In this case i'd guess it would be being asked to make a copy.
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here