How does RAII work when mixing default and non-default constructors
<p>I want to write a library wrapper class (LibWrap) around a C library that uses malloc/free. To do this I want to use C++'s RAII to allocate and free memory. I used lib_address as a random example address that I would receive from the library. However when defining my memeber variable the destructor that is called somehow has this lib_address.</p>

<p>I would expect the destructor of the member variable created by the default constructor not to know the new address that I am putting into the constructor of my replacement member variable.</p>

<pre><code>#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;
using namespace std;

class LibWrap
{
    int j;
    int lib_address;
public:
    LibWrap(): //default LibWrap
    j(0),
    lib_address(0)
    {
        cout &lt;&lt; "default LibWrap "&lt;&lt;j &lt;&lt;"\t\t"&lt;&lt;lib_address &lt;&lt; "\t" &lt;&lt; this&lt;&lt;endl;
    }

    LibWrap(int f_j): //special LibWrap
    j(0),
    lib_address(0)
    {
        j = f_j;
        lib_address = rand();
        cout &lt;&lt; "special LibWrap " &lt;&lt; j&lt;&lt;"\t"&lt;&lt; lib_address&lt;&lt; "\t" &lt;&lt; this &lt;&lt;endl;
    }

    ~LibWrap()
    {
        cout &lt;&lt; "killing LibWrap " &lt;&lt; j&lt;&lt;"\t" &lt;&lt;lib_address &lt;&lt;"\t" &lt;&lt; this&lt;&lt; endl;
    }

    int g()
    {
        return j;
    }
};

class A
{
    int i;
    LibWrap b;

public:
    A(): //default A
    i(0)
    {
        cout &lt;&lt; "default A\t"&lt;&lt;i &lt;&lt; endl;
    }

    A(int f_i)://special A
    i(0)
    {
        i = f_i;
        cout &lt;&lt; "special A\t"&lt;&lt;i &lt;&lt; endl;
        b = LibWrap(10);
    }
    ~A()
    {
        cout &lt;&lt; "killing A\t"&lt;&lt;i &lt;&lt; endl;
    }


    void p()
    {
        cout &lt;&lt;"Test values: "&lt;&lt; i&lt;&lt; "," &lt;&lt; b.g() &lt;&lt; endl;
    }
};

int f()
{
    //A a; a.p();
    cout &lt;&lt; "variable\t\tlib_address\treal_address" &lt;&lt; endl; 
    A a = A(1);
    cout &lt;&lt; "End" &lt;&lt; endl;
    //a.p();
}

int main()
{
    f();
}
</code></pre>

<p>Running this code I would expect to get the following result:</p>

<pre><code>variable        lib_address real_address
default LibWrap 0       0   0xbfef2e28
special A   1
special LibWrap 10  1804289383  0xbfef2df8 
killing LibWrap 10  1804289383  0xbfef2df8 --would expect kiling LibWrap 0  0 0xbfef2e28
End
killing A   1
killing LibWrap 10  1804289383  0xbfef2e28 --would expect killing LibWrap 10 1804289383 0xbfef2df8
</code></pre>
