Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ code gets different results in g++ and vs2008
    primarykey
    data
    text
    <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;vector&gt; using namespace std; struct Exmpl{ Exmpl() { cout &lt;&lt; "Exmpl()" &lt;&lt; endl; } Exmpl(const Exmpl&amp;) { cout &lt;&lt; "Exmpl(const Exmpl&amp;)" &lt;&lt; endl; } Exmpl&amp; operator=(const Exmpl&amp; rhs) { cout &lt;&lt; "operator=Exmpl()" &lt;&lt; endl; return *this; } ~Exmpl() { cout &lt;&lt; "~Exmpl()" &lt;&lt; endl; } }; void func1(Exmpl obj) { } void func2(Exmpl &amp;obj) { } Exmpl func3() { Exmpl obj; return obj; } int main() { Exmpl eobj; func1(eobj); func2(eobj); eobj = func3(); Exmpl *p = new Exmpl; vector&lt;Exmpl&gt; evec(3); delete p; return 0; } </code></pre> <p>when compiled in g++(4.4.3) I got </p> <pre><code>Exmpl() Exmpl(const Exmpl&amp;) ~Exmpl() Exmpl() operator=(const Exmpl&amp;) ~Exmpl() Exmpl() Exmpl() Exmpl(const Exmpl&amp;) Exmpl(const Exmpl&amp;) Exmpl(const Exmpl&amp;) ~Exmpl() ~Exmpl() ~Exmpl() ~Exmpl() ~Exmpl() ~Exmpl() </code></pre> <p>and in vs2008, the result is:</p> <pre><code>Exmpl() Exmpl(const Exmpl&amp;) ~Exmpl() Exmpl() Exmpl(const Exmpl&amp;) ~Exmpl() operator=(const Exmpl&amp;) ~Exmpl() Exmpl() Exmpl() Exmpl(const Exmpl&amp;) Exmpl(const Exmpl&amp;) Exmpl(const Exmpl&amp;) ~Exmpl() ~Exmpl() ~Exmpl() ~Exmpl() ~Exmpl() ~Exmpl() </code></pre> <p>when the code goes to "eobj = func3();" in main, the 5th and 6th lines in vs2008 result can't be found in g++. I've tried to several levels of optimize, but the result is the same. what's the reason of the difference?</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.
 

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