Unreal and Union
Why does the following ClassWithUnion compile in a clean c++ project, but not if I use it in unreal?
I get the following error upon compilation: error C4582: 'ClassWithUnion::data': constructor is not implicitly called
No, I cannot avoid using these constructs.
Long Version: The error is kind of correct because it's being explicilty called... But it is valid C++ to do it like this, which I confirmed by creating an empty project with just that class. That one does compile without problems and the expected behavior.
I'm trying to use the OpenSource CActorFramework, which is making extensive use of anonymous unions for varius purposes. Mainly to avoid calling constructors in cases where it is not required or would lead to invalid behavior if they were called. So sadly not using those unions would pretty much mean not using the Framework at all or having to rewrite large parts of the framework, which would kind of defeat the purpose of using it in the first place.
I'm on Windows 7 and tried compiling with Visual Studio 2015 and 2017 but neither changed the result.
The main goal of using the Framework was to use it for large scale background simulation of an abstract game world. Actors that would leave the sphere around the player would be simulated using the more efficent and slimed down message passing interface implemented by the CAF. This would not happen in real time but instead discrete time steps for various buckets of the world. Actors close to the player sphere would then be simulated in real time by UE4. Sadly since i can't get it to compile together with UE4 that's apparently not going to happen anytime soon.
I've found that hidding CAF behind a dll and then linking that into the project worked, but that heavly limits the usefullnes and requires me to duplicate, (or even triple) certain classes because i can't directly use them due to having to hide the CAF definitions. Also base types like FVector would have to be reimplemented within the dll requiring additional work. (And more duplicates...)
So if you have either an idea why that compiler error happens in ue4 or an alternative open source framework for simulating my actors in the background, that would be much appreciated.
Presumably the problem is that VC doesn't enable that warning by default, and UE4 does, and also enables warnings-as-errors. VC is correct to warn, IMHO, so we wouldn't want to disable that warning. I would recommend writing your class like this:
This makes it clear that you don't want an instance of
Alternatively, you can disable the warning number in your copy of WindowsPlatformCompilerSetup.h, but you will need to keep this up to date whenever you update your engine version.
Hope this helps,
answered Jul 06 '17 at 05:24 PM
Steve Robb STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here