Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first one is easy:</p> <pre><code>AutoA b_auto_to_a_auto(b_auto); //fails to compile </code></pre> <p>This fails on VC6 since it requires <em>member function templates</em>, something VC6's standard library doesn't support. It compiles on standard-compliant compilers, though.</p> <p>Workaround:</p> <pre><code>AutoA b_auto_to_a_auto( b_auto.release() ); </code></pre> <p>The second one is much more subtle :)</p> <pre><code>sink(b_raw_to_b_auto); //fails to compile </code></pre> <p>This one shouldn't compile on a standards-compliant compiler, because there's an implicit conversion going on. The compiler turns the above into</p> <pre><code>sink( std::auto_ptr&lt;A&gt;( b_raw_to_b_auto ) ); </code></pre> <p>however, <code>sink</code> takes <code>std::auto_ptr&lt;A&gt;</code> <em>by</em> <em>value</em>, so the temporary <code>std::auto_ptr&lt;A&gt;</code> created implicitly by the compiler needs to be <em>copy-constructed</em> into the argument to <code>sink</code>. Now, temporaries like that are <em>rvalues</em>. Rvalues don't bind to non-const references, but <code>std::auto_ptr</code>'s "copy constructor" takes it's argument by <em>non-const</em> reference.</p> <p>There you go - compile error. AFAICS this is standards-conforming behaviour. C++-0x "move semantics" will fix that by adding a "copy constructor" that takes an rvalue reference, though I'm not sure how much love <code>std::auto_ptr</code> will still receive in the future, what with <code>std::shared_ptr</code> and all.</p> <p>Workaround for the second one:</p> <pre><code>AutoA tmp( b_raw_to_b_auto/*.release() for VC6*/ ); sink( tmp ); </code></pre>
    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.
 

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