title: Why do we need to delete pointers inside copy assignment operator
body: <p>I have seen several examples of copy assignment operator and could not understand why do we need to delete pointers inside copy assignment operator. For example if I have the following class</p>
  
  <pre><code> class MyClass
   {
    public:
      MyClass(int a)
      {
        x = new int(a);
      }
      MyClass&amp; operator=(const MyClass&amp; pMyClass)
      {
         *x = *(pMyClass.x);
  
         // ?????????
         // delete x;
         // x = new int(*(pMyClass.x));
      }
      ~MyClass()
      {
         delete x;
      }
    private:
      int* x;
   }
  </code></pre>
  
  <p>What is wrong with *x = *(pMyClass.x) line? I am just copying object pointed by pMyClass.x why I need to delete and create it again?. Could anyone please give example when this code will cause memory leak?</p>