Jump to content
  • Advertisement

jeroenb

Member
  • Content count

    514
  • Joined

  • Last visited

Community Reputation

282 Neutral

About jeroenb

  • Rank
    Advanced Member

Personal Information

  1. jeroenb

    Linux for game development

    I was also new to Linux development for my engine. After some investigations and the 'popularity' of Ubuntu at that time, I decided to go for that platform. Luckily it wasn't a bad experience, most libraries I used in my engine (which I originally developed with Windows) were readily available as package in the package manager. The main difficulties I experienced were getting my project generator (premake) and debugger up and running (which still isn't running as nicely as visual studio) and obviously the small differences in API's.
  2. jeroenb

    Non-trivial union

    Right, I fixed that in my code. I think I got it working with the proposal I made myself. It works both with GCC and visual studio. E.g.: Type(const Type& that) : mKind(eObject), mObject() { if ( that.mKind == eArray ) { mKind = eArray; new (&mArray.mType) std::unique_ptr<Type>(new Type())); mArray.mDimension = 1; } else { mObject.mName = that.eObject.mName; } }
  3. jeroenb

    Non-trivial union

    The Type class is used in my custom script language to specify the type of for example a variable, class, function argument, etc. To preserve memory I wanted to give this new C++11 functionality a try as that would prevent memory allocations of the structs in case a pointer is used.
  4. I am trying to get my head around the new C++11 non-trivial unions in Visual Studio 2015. Please have a look at a simplified class I created (note that this code might not compile in its current form): class Type { public: Type() : mKind(eObject), mObject() { } ? // move constructor and operator= removed Type(const Type& that) : mKind(eObject), mObject() { if ( that.mKind == eArray ) { mKind = eArray; mArray.mDimension = 1; mArray.mType.reset(new Type()); // <-- here I get crashes due to uninitialized mType } else { mObject.mName = that.eObject.mName; } } enum Kind { eArray, eObject } mKind; struct ArrayInfo { std::unique_ptr<Type> mType; int mDimension; }; struct ObjectInfo { String mName; }; union { ArrayInfo mArray; ObjectInfo mObject; }; } I read that you may only initialize one member of the union (otherwise the constructor is ill formed). In this case I choose the mObject variable. Compiling works fine and well, but at runtime when I try to assign values to the mArray part I get crashes as it seems that it has not been initialized. I have looked through numerous resources about non-trivial unions and they always only have a std::string in there. Now I wonder how I can make this work. Do I need something like: mObject.~String(); new (&mArray) ArrayInfo(); Thanks for the help.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!