title: Why isn't the user-defined copy constructor invoked?
body: <p>See the code in <a href="http://cpp.sh/8bsdl" rel="nofollow noreferrer">http://cpp.sh/8bsdl</a>:</p>
  <pre><code>// copy constructor: deep copy
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class Example5 {
      string* ptr;
    public:
      Example5 (const string&amp; str) : ptr(new string(str)) {cout &lt;&lt; &quot;constructor&quot; &lt;&lt; '\n';}
      ~Example5 () {delete ptr;}
      // copy constructor:
      Example5 (const Example5&amp; x) : ptr(new string(x.content())) {cout &lt;&lt; &quot;copy constructor&quot; &lt;&lt; '\n';}
      // access content:
      const string&amp; content() const {return *ptr;}
  };
  
  int main () {
      // cout &lt;&lt; &quot;copy constructor&quot; &lt;&lt; '\n';
    Example5 foo (&quot;Example1&quot;);
    Example5 baz (&quot;Example2&quot;);
    Example5 bar = foo; // default copy constructor
    bar = baz; // default copy assignment
  
    cout &lt;&lt; &quot;bar's content: &quot; &lt;&lt; bar.content() &lt;&lt; '\n';
    return 0;
  }
  </code></pre>
  <p>I defined a customized copy constructor, but it seems that it never gets called (In fact, the program doesn't produce any output, not even from the constructor...).</p>
  <p>The same thing happens when I commented out line 12 where I hope to invoke the default copy constructor. Can anyone tell me what's wrong here?</p>