title: Need Help Deallocating Memory in a Class Destructor
body: <p>I receive the following error when I run my test program:</p>
  
  <p><img src="https://i.stack.imgur.com/Nmhfs.png" alt="http://i.stack.imgur.com/Nmhfs.png"></p>
  
  <p>The error goes away if I comment out "delete name," but I can't seem to figure out why. Hopefully someone can give me insight into a solution.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  using namespace std;
  
  class Shape
  {
  protected:
      string* name = new string;
  public:
      Shape(string str)
      {
          *name = str; 
      }
      ~Shape()
      {
          delete name;  //Why does my program run if I comment this out?
          name = NULL;
      }
  
      virtual double getArea() const
          { return 0; }
      void setName(string str)
          { *name = str; }
      string getName() const
          { return *name; }
  };
  
  class Circle : public Shape
  {
  private:
      double radius;
  public:
      Circle(string str = "", double r = 0) : Shape(str)
          { radius = r; }
      void setRadius(double r)
          { radius = r; }
      double getRadius() const
          { return radius; }
      virtual double getArea() const
          { return radius * radius * 3.14; }
  
      Circle operator= (const Circle &amp;);
      Circle operator+ (const Circle &amp;);
  };
  
  Circle Circle::operator= (const Circle &amp;right)
  {
      radius = right.radius;
      return *this;
  }
  
  Circle Circle::operator+ (const Circle &amp;right)
  {
      Circle tempCircle;
      tempCircle.radius = radius + right.radius;
      return tempCircle;
  }
  
  int main()
  {
      Circle c1("c1",5);
      Circle c2("c2",10);
      Circle c3;
  
      c3 = c2 + c1;
  
      cout &lt;&lt; "c1" &lt;&lt; c1.getRadius() &lt;&lt; endl;
      cout &lt;&lt; "c2" &lt;&lt; c2.getRadius() &lt;&lt; endl;
      cout &lt;&lt; "c3" &lt;&lt; c3.getRadius() &lt;&lt; endl;
      return 0;
  }
  </code></pre>