<br><br><div class="gmail_quote">On Tue, Sep 25, 2012 at 6:26 PM, Ladislav Nevery <span dir="ltr"><<a href="mailto:neuralll@gmail.com" target="_blank">neuralll@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div id=":1u0">int a=1;<br>
a=2;<br>
<br>
The moment I agreed to assign new value I agreed to old value being lost.<br>
This is normal and expected behavior.</div></blockquote></div><br><div>For the value yes, but not for the destructor call.</div><div><br></div><div>If my understanding is correct, if I have this kind of code:</div><div><br>
</div><div><div><br></div><div>class TextFile</div><div>{</div><div>public:</div><div>   TextFile( std::string path )</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>  m_file.open( path );</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span> // add checks here</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">    </span></div>
<div>   ~TextFile()</div><div>   {</div><div>      m_file.close(); </div><div>   }</div><div>   </div><div>   TextFile& operator=( const TextFile& other )</div><div>   {</div><div>       // clear our file's content</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>   m_file.clear();</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>   // copy the content of other's file</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>   m_file.write( other.m_file );</div>
<div>   }</div><div><br></div><div>private:</div><div><br></div><div>   FileHandler m_file;</div><div><br></div><div>};</div></div><div><br></div><div>Then the standard guarantee me that the destructor will be called only if the instance goes out of scope, not on copy or move.</div>
<div>If I understand correctly what you propose, this code wouldn't do what I assume it would. It would call the destructor and then change the semantic of the type.</div><div><br></div><div>Joel Lamotte</div>