title: Why is constructor invoked in assignment operation?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  using namespace std;
  class MyString : public string {
  public:
      MyString(const char* s) :string(s) {}
      MyString(const string&amp; str) : string(str) { cout &lt;&lt; &quot;why is this line invoked?&quot;; }
  };
  int main() {
      MyString s1(&quot;s1-&quot;), s2(&quot;s2-&quot;);
      s2 = s1+s2; //I thought this line would be an assignment operation for s2. Not sure why constructor from line 7 is invoked?
      return 0;
  }
  </code></pre>
  <p>I tried to inherit <code>MyString</code> class from <code>string class</code>. I wonder why <code>s2=s1+s2</code> would invoke constructor from <code>MyString</code>. Isn't it an assignment operation, instead of an initialization? Thank you!!</p>