vendredi 29 juin 2018

Initializing a union with anonymous structs

I am merging together a tree structure into a library. The library in question has a compile time check prevent users from leaving uninitialized variables while merging, among other checks. The tree structure I am trying to merge has the a structure like

struct TreeNode
{
  int Dimension;
  int ChildIndex;
  union {
    struct
    { 
      float LMax;
      float RMin;
    } Node;
    struct
    {
      int Start;
      int Size;
    } Leaf;
  };

  TreeNode()
    : Dimension()
    , ChildIndex()
  {}
};

When I have this class merged, and I compile the library, I get -Wmissing-field-initializers warnings for the union which is not initialized by me.

I am looking for a way to initialize the union in the constructor of the TreeNode. Can anyone please point me to how this could be done? I also seek advice if the TreeNode can be structured in a better way.

Aucun commentaire:

Enregistrer un commentaire