Why does this create Data object twice?
<p>I came across the following problem recently and unfortunately, I'm unable to understand why Data object is created twice in the following code.</p>

<p>I thought that once _data = i is executed in Base(_data = i ), it will be available until Derived is destroyed but as the output indicates, it's not the case.</p>

<p>Would appreciate a logical explanation that would help me understand the concept.</p>

<pre><code>struct Data
{
    Data(int i_ = 0 ) : _i(i_) { cout &lt;&lt; "Inside Data::ctor" &lt;&lt; endl; }
    ~Data() { cout &lt;&lt; "Inside Data::dtor" &lt;&lt; endl ; }

    int _i;
};

struct Info
{
    Info(Data* d_)
    {
            cout &lt;&lt; "Inside Info::ctor" &lt;&lt; endl;
            cout &lt;&lt; d_-&gt;_i &lt;&lt; endl ;
            d_-&gt;_i = 1;
    }

};

struct Base
{
    Base(const Data&amp; data_)
    {
            cout &lt;&lt; "Inside Base::ctor" &lt;&lt; endl;
            cout &lt;&lt; data_._i &lt;&lt; endl;
    }
};

struct Derived : public Base
{
    Derived(int i_) : _info(&amp;_data), Base(_data = i_)
    {
            cout &lt;&lt; "Inside Derived::ctor" &lt;&lt; endl;
            cout &lt;&lt; _data._i &lt;&lt; endl ;
    }

    Data _data;
    Info _info;
};

int main()
{
    Derived d(100);

    return 0;
}
</code></pre>

<p>Output is :</p>

<pre><code>Inside Data::ctor
Inside Base::ctor
100
Inside Data::dtor
Inside Data::ctor
Inside Info::ctor
0
Inside Derived::ctor
1
Inside Data::dtor
</code></pre>
