title: Overloading the C++ assignment operator
body: <p>I want to extend the <code>std::string</code> with some functionality, so I derive my <code>String</code> from it. In order to make code like <code>String str = stdStr;</code> work, I've tried to overload the assignment operator, but my code is not being called for some reason. How can I fix it?</p>
  
  <pre><code>#include &lt;string&gt;
  
  class String
      :
          public std::string
  {
  
      public:
          /*
          I do know that this constructor will solve the problem, but is it possible to use the operator?
  
          String ( const std::string&amp; stdString )
          {
  
              ...
  
          }
          */
  
          String&amp; operator= ( const std::string&amp; stdString )
          {
              ...
              return *this;
          }
  
  };
  
  int main()
  {
  
      std::string foo = "foo";
      String bar = foo;
  
      return 1;
  
  }
  </code></pre>