Why this copy-constructor is invoked in the program?
<pre><code>#include &lt;iostream&gt;
#include &lt;string.h&gt;

using namespace std;

class withCC
{
public:
    withCC() {}
    withCC(const withCC&amp;) {
        cout&lt;&lt;"withCC(withCC&amp;)"&lt;&lt;endl;
    }
};

class woCC
{
    enum {bsz = 100};
    char buf[bsz];
public:
    woCC(const char* msg = 0) {
        memset(buf, 0, bsz);
        if(msg) strncpy(buf, msg, bsz);
    }
    void print(const char* msg = 0)const {
        if(msg) cout&lt;&lt;msg&lt;&lt;":";
        cout&lt;&lt;buf&lt;&lt;endl;
    }
};

class composite
{
    withCC WITHCC;
    woCC WOCC;
public:
    composite() : WOCC("composite()") {}
    void print(const char* msg = 0) {
        cout&lt;&lt;"in composite:"&lt;&lt;endl;
        WOCC.print(msg);
    }
};

int main()
{
    composite c;
    c.print("contents of c");
    cout&lt;&lt;"calling composite copy-constructor"&lt;&lt;endl;
    composite c2 = c;
    c2.print("contents of c2");
}
</code></pre>

<p>The running result is below:</p>

<pre><code>$ ./a.out 
in composite:
contents of c:composite()
calling composite copy-constructor
withCC(withCC&amp;)
in composite:
contents of c2:composite()
</code></pre>

<p>And I don't understand why <code>withCC(withCC&amp;)</code> is given as part of output. I guess <code>composite c2 = c;</code> causes copy-constructor to be executed. But as below shown, <code>WITHCC</code> is part of <code>class composite</code>, why it will be invoked to handle this copy-constructor? Thanks!</p>
