title: C++ class access level
body: <p>Suppose I have two classes. One called Point:    </p>
  
  <pre><code>class Point{
      public:
          Point(): x_(0), y_(0) {}
      protected: 
          int x_, y_;
      };
  </code></pre>
  
  <p>Then I have another class, which derives from Point:</p>
  
  <pre><code>class Point3D : public Point {
  public:
      Point3D(): Point(), z_(0){}
      double distance(Point3D pt, Point base) const;
  protected:
      int z_;
  };
  
  double Point3D::distance(Point3D pt, Point base) const
  {
      int dist_x, dist_y;
      dist_x = base.x_ - x_;
      dist_y = base.y_ - y_;
  
      return sqrt(dist_x * dist_x +
                  dist_y * dist_y);
  }
  </code></pre>
  
  <p>Then I got error like: base.x_ is protected within this context. But the access level of Point3D to Point is public, plus the x_ data member in Point is protected. So it is supposed to be error-free, right? Can someone please help me clear this out?</p>