Assigning base struct to derived struct
<p>I use a struct to represent data that is written to a file. If I need to add members to this struct (i.e. save out extra data) I create a new struct (this represents a new version of the dataset) that derives from the original one. So for example:</p>

<pre><code>struct data1
{
   int stuff1;
   int stuff2;
};

struct data : data1
{
   int stuff3;
};
</code></pre>

<p>Backward compatibility is maintained by checking if we're loading <code>data1</code>, and if so, convert it to <code>data</code> (and value-initialize only those new members in <code>data</code>). What would be the best way to do this? Here is what I've started:</p>

<pre><code>if( loaded_data.size() == sizeof(data1) ) {
    // Old data format detected, upgrade to new structure
    data d = data(); // value-initialize everything
    // TODO: Assign 'data1' to 'data'
}
</code></pre>

<p>I've thought of putting a constructor in <code>data</code> to copy from a <code>data1</code>, but then that breaks the free value-initialization I get (I'd have to implement my own default constructor at that point). Should I use memcpy(), or is there a better more built-in way (perhaps some trick with copy semantics)?</p>
