Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your original struct without constructors was an aggregate type and therefore allowed you to use aggregate initialization. Types with user provided constructors are not aggregates, so adding the constructor broke your use of aggregate initialization. In fact declaring that constructor causes it to be the only constructor and prevents you from initializing instances of that type any way other than with that constructor.</p> <p>In order to have such a constructor but also have the ability to initialize instances of that type in other ways, you have to declare other constructors with the desired behavior. If you want to be able to initialize a and b you can do something like the following:</p> <pre><code>struct A { int a,b; A(){} A(int a_, int b_) : a(a_), b(b_) {} }; </code></pre> <hr> <p>Note that I haven't mentioned anything about Uniform Initialization. None of the above is in any way dependent on Uniform Initialization or C++11. Where Uniform Initialization comes in is the specific syntax available to initialize objects.</p> <p>In C++03 aggregate initialization looked only like:</p> <pre><code>S s = {1, 2}; </code></pre> <p>And in C++03 using a constructor looked like:</p> <pre><code>S s(1, 2); </code></pre> <p>Uniform Initialization introduced the ability to use the same syntax for different types of initialization. I.e. Uniform Initialization can be used for aggregate initialization and initialization via constructors.</p> <p>Thus in C++11 you can use the syntax:</p> <pre><code>A a{1, 2}; </code></pre> <p>and this may be aggregate initialization if the type is an aggregate, or it may call a constructor if the type has constructors. Since you were using Uniform Initialization to initialize an aggregate, in order to continue using that syntax with a non-aggregate type you simply have to define an appropriate constructor.</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. 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.
    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