Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From the standard. "To default-initialize an object of type T means: -- if T is a non-POD class type [the case like vector], the default constructor for T is called."</p> <p>The constructor notation <code>T()</code> is used to express the default value of type T and that this is zero for built in types and the default constructor for user-defined types. The construct <code>POD()</code> produces value initialisation and according to the stdandard, which results in all members and sub members being either default constructed or zero initialised.</p> <p>This is why your statement is legal, but is it zero initialized as per the standard; needs some detailed lookup IMHO.</p> <p>BUT, i could not find in the standard where the it <strong>defines</strong> the <em>meaning of default construction for built in types</em>.</p> <p><strong>EDIT:-</strong></p> <pre><code>struct S { int x; }; void f () { S s1; // s1.x is uninitialized here S s2 = S(); // s2.x is zero here } </code></pre> <p>I think we often make up our own interpretation of what default construction applied to built in types means; because the C++ standard doesn't define it (atleast i could not find it) and i remember <em>Stroustrup</em> or <em>Josuttis</em> say that it means <code>T()</code> which is described as being value initialisation is "<strong>zero converted to type T</strong>" for built in types.</p> <p>Since <code>int*</code> is a built-in type it is initialized to zero.</p> <p>But i am really not sure.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload