Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The behavior of your code depends critically on the compiler you are using. More precisely, it depends on which version of language specification your compiler implements.</p> <p>For C++98 compilers, both declarations have identical effect on the final values of the objects being declared: the <code>str</code> member should become empty, while the <code>num</code> members should contain unpredictable value. In both cases the actual initialization is <em>default-initialization</em> performed by a compiler-provided default constructor of class <code>temp</code>. That default constructor initializes <code>str</code>, but leaves <code>num</code> uninitialized.</p> <p>For C++03 compilers the behavior is different. There's no difference for <code>temp1</code> object (its <code>num</code> is still unpredictable). But <code>temp2</code> initialization is handled differently. In C++03 the <code>()</code> initializer triggers the new kind of initialization - so called <em>value-initialization</em>. Value-initialization ignores the compiler-provided default constructor of the top level object, and instead works directly on its subobjects (data members in this case). So the <code>temp2</code> object is effectively initialized by value-initialization, which also sets the <code>num</code> member to zero (in addition to initializing <code>str</code> with an empty string). For this reason, <code>temp2.num</code> ends up being zero in C++03 compilers.</p> <p>If in your experiments you observed consistent zero in <code>temp2.num</code>, it means that your compiler follows the C++03 specification in this respect.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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