title: Have shape and circle class, and point class. Segmentation fault when creating circle with point class as one parameter
body: <p>Here is my Shape.h. Ignore all the code that is commented out. That is from a version that I believe was incorrect but I left it in there in case I was wrong.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;math.h&gt;
  #include "Point.h"
  
  
  using namespace std;
  
  class Shape {
      public:
  
          Shape() {}
          virtual ~Shape() {}
  
          /*
          virtual float calcArea(const Shape&amp; s) const = 0;
          virtual float calcCircum(const Shape&amp; s) const = 0;
          virtual string calcBox(const Shape&amp; s) const = 0;
          virtual void display(const Shape&amp; s) const = 0;
          */
  
              virtual float calcArea() const = 0;
              virtual float calcCircum() const = 0;
              virtual string calcBox() const = 0;
              virtual void display() const = 0;
  
  };
  
  class Circle : public Shape {
      public:
      int radius;
      int pointX;
      int pointY;
      Point *middlePoint;
      float PI;
  
      Circle() : Shape() {
          middlePoint = new Point(0,0);
          radius = 0;
      }
      ~Circle() {}
  
      Circle(int rad, Point&amp; p) : Shape() {
          PI = 3.141592;
          *middlePoint = p;
          pointX = p.getX();
          pointY = p.getY();
          radius = rad;
      }
  
      // float calcArea(const Circle&amp; s) const {
      float calcArea() const {
          float tempArea;
      //  tempArea = PI * s.radius * s.radius;
      tempArea = PI * radius * radius;
          return tempArea;
          }
  
      // float calcCircum(const Circle&amp; s) const {
      float calcCircum() const {
      //  int diameter = 2 * s.radius;
      int diameter = 2 * radius;
          float tempCircum;
          tempCircum = PI * diameter;
          return tempCircum;
  
      }
  
      // string calcBox(const Circle&amp; s) const {
      string calcBox() const {
  //      int x = s.pointX;
  //      int y = s.pointY;
  //      int r = s.radius;
      int x = pointX;
      int y = pointY;
      int r = radius;
          int tlX = x - r;
          int tlY = y + r;
  
          int blX = x - r;
          int blY = y - r;
  
          int trX = x + r;
          int trY = y + r;
  
          int brX = x + r;
          int brY = y - r;
  
          Point *topLeft = new Point(tlX,tlY);
          Point *bottomLeft = new Point(blX,blY);
          Point *topRight = new Point(trX,trY);
          Point *bottomRight = new Point(brX,brY);
  
          stringstream output;
          string tempOut;
          output &lt;&lt; *topLeft &lt;&lt; *bottomLeft &lt;&lt; *topRight &lt;&lt; *bottomRight;
          tempOut = output.str();
          return tempOut;
  
      }
  
      // void display(const Circle&amp; s) const {
      void display() const {
          cout &lt;&lt; "Class Name: Circle" &lt;&lt; endl;
  //      float tmpArea = calcArea(s);
      float tmpArea = calcArea();
          cout &lt;&lt; "Area = " &lt;&lt; tmpArea &lt;&lt; endl;
  //      cout &lt;&lt; "Radius = " &lt;&lt; s.radius &lt;&lt; endl;
      cout &lt;&lt; "Radius = " &lt;&lt; radius &lt;&lt; endl;
  //      float tmpCircum = calcCircum(s);
      float tmpCircum = calcCircum();
          cout &lt;&lt; "Circumference = " &lt;&lt; tmpCircum &lt;&lt; endl;
          cout &lt;&lt;"Middle Point = " &lt;&lt; middlePoint;
  //      string bbox = calcBox(s);
      string bbox = calcBox();
          cout &lt;&lt;"Bounding Box Points = " &lt;&lt; bbox;
      }
  };
  </code></pre>
  
  <p><hr>
  Here is my TMA4Question1.cpp code.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;math.h&gt;
  #include "Shape.h"
  
  int main() {
  
      Point *circlePoint = new Point(10,-5);
  
      Circle *mainCircle = new Circle(23,*circlePoint);
  }
  </code></pre>
  
  <p>Ok. Yes this is a homework assignment for University. I'm not looking just for the answer, I would like to know why this program gives me a segmentation fault and how to correct it.</p>
  
  <p>I know the error is in the Circle code, where I pass a pointer to the circlePOint in the constructor for the Circle class. I dont know why it generates a seg fault. I hope someone can provide some insight. Thanks.</p>
  
  <p>Sorry if the code is messy. Had a hard time pasting it into here properly with 4 spaces and all that.</p>