Erase all members of a class
<p>Yesterday I read some code of a colleague and came across this:</p>

<pre><code>class a_class
{
public:
    a_class() {...}
    int some_method(int some_param) {...}

    int value_1;
    int value_2;
    float value_3;
    std::vector&lt;some_other_class*&gt; even_more_values;
    /* and so on */
 }

 a_class a_instances[10];

 void some_function()
 {
     do_stuff();
     do_more_stuff();

     memset(a_instances, 0, 10 * sizeof(a_class)); // &lt;===== WTF?
 }
</code></pre>

<p>Is that legal (the WTF line, not the public attributes)? To me it smells really, really bad...
The code ran fine when compiled with VC8, but it throws an "unexpected exception" when compiled with VC9 when calling <code>a_instances[0].event_more_values.push_back(whatever)</code>, but when accessing any of the other members. Any insights?</p>

<p>EDIT: Changed the memset from <code>memset(&amp;a_instances...</code> to <code>memset(a_instances...</code>. Thanks for pointing it out Eduard.<br />
EDIT2: Removed the ctor's return type. Thanks litb.</p>

<p>Conclusion: Thanks folks, you confirmed my suspicion.</p>
