title: Why doesn't a derived class use the base class operator= (assignment operator)?
body: <p>Following is a simplified version of an actual problem. Rather than call <code>Base::operator=(int)</code>, the code appears to generate a temporary <code>Derived</code> object and copy that instead. Why doesn't the base assignment operator get used, since the function signature seems to match perfectly? This simplified example doesn't display any ill effects, but the original code has a side-effect in the destructor that causes all kinds of havoc.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Base
  {
  public:
     Base()
     {
        cout &lt;&lt; "Base()\n";
     }
  
     Base(int)
     {
        cout &lt;&lt; "Base(int)\n";
     }
  
     ~Base()
     {
        cout &lt;&lt; "~Base()\n";
     }
  
     Base&amp; operator=(int)
     {
        cout &lt;&lt; "Base::operator=(int)\n";
        return *this;
     }
  };
  
  class Derived : public Base
  {
  public:
     Derived()
     {
        cout &lt;&lt; "Derived()\n";
     }
  
     explicit Derived(int n) : Base(n)
     {
        cout &lt;&lt; "Derived(int)\n";
     }
  
     ~Derived()
     {
        cout &lt;&lt; "~Derived()\n";
     }
  };
  
  class Holder
  {
  public:
     Holder(int n)
     {
        member = n;
     }
  
     Derived member;
  };
  
  int main(int argc, char* argv[])
  {
     cout &lt;&lt; "Start\n";
     Holder obj(1);
     cout &lt;&lt; "Finish\n";
  
     return 0;
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>Start
  Base()
  Derived()
  Base(int)
  Derived(int)
  ~Derived()
  ~Base()
  Finish
  ~Derived()
  ~Base()
  </code></pre>
  
  <p><a href="http://ideone.com/TAR2S" rel="noreferrer">http://ideone.com/TAR2S</a></p>