title: c++ - error: member access into incomplete type in base class virtual function
body: <p>I have a base class <code>Shape</code> and it has a virtual function <code>intersect()</code>.</p>
  
  <p>The <code>HitRecord</code> is a struct defined in the same <code>.h</code> file.</p>
  
  <p>Also, <code>Shape</code> has a child class <code>Triangle</code>. I'm trying to access a member of <code>HitRecord</code> in <code>Shape::intersect()</code> but I got an error <code>error: member access into incomplete type in base class virtual function</code></p>
  
  <p>It is strange that I could do this in the child class but can't in the base class.</p>
  
  <p>Does it because of it's a <strong>virtual</strong> function?</p>
  
  <p><strong>Note:</strong> Another strange thing: I can run on my Ubuntu 16.04 but encounter this error on my mac.</p>
  
  <p><strong>code</strong></p>
  
  <pre><code>struct HitRecord;   // forward declaration
  
  class Shape {
  public:
      virtual bool intersect(Ray&amp; r, HitRecord&amp; rec) {
          std::cout &lt;&lt; "Child intersect() is not implement." &lt;&lt; std::endl;
          rec.obj = this;
          return false;
      }
  }
  
  struct HitRecord {
      float t;
      vec3f p;    // point coord
      vec3f norm;
      Shape* obj;
  };
  
  class Triangle: public Shape {
  public:
      Mesh* mesh_ptr;
      unsigned int vertexIndex[3];
  
      Triangle() {...}
  
      Triangle(Mesh* m) {...}
  
      inline bool intersect(Ray&amp; r, HitRecord&amp; rec);
  }
  
  inline bool Triangle::intersect(Ray&amp; r, HitRecord&amp; rec) {
      vec3f n = cross(v1-v0, v2-v0);
      float t = - (dot(n, r.origin())+d) / dot(n, r.direction());
      vec3f p = r.origin() + t*r.direction();
  
      rec.t = t;
      rec.p = p;
      rec.norm = unit(n);
      rec.obj = this;
      return true;
  }
  </code></pre>