Vectors, "virtual", Segmentation Fault on function call
<p>I'm getting a Segmentation Fault when trying to call a function that is within a object that is part of a vector of "Shape" Pointers</p>

<p>My problem is in this function::</p>

<pre><code>    Point findIntersection(Point p, Point vecDir, int *status)
    {

        Point noPt;
        for (int i = 0; i &lt; shapes.size(); i++)
        {
         Point temp;
         cout &lt;&lt; "Shapes size" &lt;&lt; shapes.size() &lt;&lt; endl;
**SEGMENTATIONFAULT HERE &gt;&gt;&gt;&gt;&gt;**         bool intersect = shapes[0]-&gt;checkIntersect(p, vecDir, &amp;temp);
         if (intersect)
         {
          *status = 1; // Code 1 for intersecting the actual shape
          return temp;
         }

        }

        return noPt;
    }
</code></pre>

<p>Initially, I am only adding one shape:</p>

<pre><code>void createScene()
{

    image = QImage(width, height, 32); // 32 Bit

    Sphere s(Point(0.0,0.0,-50.0), 40.0);
    shapes.push_back(&amp;s);
    cout &lt;&lt; shapes.size() &lt;&lt;endl;
}
</code></pre>

<p>So I have a vector of "shapes" which is global.
vector shapes;</p>

<p>I have a class shape</p>

<pre><code>#include "Point.h"
#ifndef SHAPE_H
#define SHAPE_H
using namespace std;
class Shape
{
    public: 
    Shape() {}
    ~Shape(){}
    virtual bool checkIntersect(Point p, Point d, Point *temp) {}; // If intersects, return true else false.
    virtual void printstuff() {};

};
#endif
</code></pre>

<p>and also a Sphere class</p>

<pre><code>#include "shape.h"
#include &lt;math.h&gt;
#include &lt;algorithm&gt;
using std::cout;
using std:: endl;
using std::min;

class Sphere : public Shape
{
    public:
    Point centerPt;
    double radius;

    Sphere(Point center, double rad)
    {
     centerPt = center;
     radius = rad;
    }

    bool checkIntersect(Point p, Point vecDir, Point *temp)
    {
     cout &lt;&lt; "Hi" &lt;&lt; endl;
    /*
     Point _D = p - centerPt;
     double a = Point :: dot(vecDir, vecDir);
     double b = 2 * ( Point :: dot(vecDir, _D) );
     double c = (Point :: dot(_D,_D)) - (radius * radius);

     // Quadratic Equation
     double tempNum = b * b - 4 * a * c;
     if (tempNum &lt; 0)
     {
      return false;
     } else
     {
      double t1 = ( -b + sqrt(tempNum) ) / (2 * a);
      double t2 = ( -b - sqrt(tempNum) ) / (2 * a);
      double t;

      if (t1 &lt; 0 &amp;&amp; t2 &gt; 0) { t = t2; }
      else if (t2 &lt; 0 &amp;&amp; t1 &gt; 0) { t = t1; }
      else if ( t1 &lt; 0 &amp;&amp; t2 &lt; 0 ) { return false; }
      else
      {
       t = min(t1, t2);
      }

      Point p1 = p + (vecDir * t);

      if (p1.z &gt; 0)   // Above our camera
      {
       return false;
      } else 
      {
       temp = &amp;p1;
       return true;
      }

     }
    */
     return false;
    }
};
</code></pre>
