Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's probably not the latest, but my C++0x draft standard from June 2008 says you can do the following:</p> <pre><code>auto x = 5; // OK: x has type int const auto *v = &amp;x, u = 6; // OK: v has type const int*, u has type const int </code></pre> <p>So unless something has changed from June this is (or will be) permitted in a limited form with a pretty intuitive interpretation.</p> <p>The limitation is that if you do want to string multiple auto declarations like this (using the example above), it works because the inferred type of <code>v</code> and <code>u</code> have the same 'base type' (int in this case) to use an inexact term.</p> <p>If you want the precise rule, The draft standard says this:</p> <blockquote> <p>If the list of declarators contains more than one declarator, the type of each declared variable is determined as described above. If the type deduced for the template parameter U is not the same in each deduction, the program is ill-formed.</p> </blockquote> <p>where the "deduced template parameter U" is determined by:</p> <blockquote> <p>the deduced type of the parameter u in the call f(expr) of the following invented function template:</p> <pre><code> `template &lt;class U&gt; void f(const U&amp; u);` </code></pre> </blockquote> <p>Why they've come up with this rule instead of saying something like:</p> <pre><code>auto a = 10, b = 3.f , * c = new Class(); </code></pre> <p>is equivalent to:</p> <pre><code>auto a = 10; auto b = 3.f; auto * c = new Class(); </code></pre> <p>I don't know. But I don't write compilers. Probably something to do with once you've figured out the the <code>auto</code> keyword replaces, you can't change it in the same statement.</p> <p>Take for example:</p> <pre><code>int x = 5; CFoo * c = new CFoo(); auto a1 = x, b1 = c; // why should this be permitted if int a2 = x, CFoo* b2 = c; // this is not? </code></pre> <p>In any case, I'm not a fan of putting multiple declarations on the same statement anyway.</p>
    singulars
    1. This table or related slice is empty.
    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