#ifndef _POINT_H_ #define _POINT_H_ #include class Point { public: // Try removing the initializer for refExample, // either setting it in the body of the constructor // or trying to leave it uninitialized... Point(const int x, const int y) : refExample(x) { x_ = x; y_ = y; // refExample = x; // why doesn't this work? } int get_x() const { return x_; } // inline member function int get_y() const { return y_; } // inline member function void SetLocation(const int x, const int y) { x_ = x; y_ = y; } // inline member function double Distance(const Point &p) const; // member function private: int x_; // data member -- now a reference, bizarrely int y_; // data member //------------------------------------------------------------------ const int &refExample; // Just to show issue with a ref member //------------------------------------------------------------------ }; // class Point inline double Point::Distance(const Point &p) const { // We can access p’s x_ and y_ variables either through the // get_x(), get_y() accessor functions, or the x_, y_ private // member variables directly, since we’re in a member function of // the same class. double distance = (x_ - p.get_x()) * (x_ - p.get_x()); distance += (y_ - p.y_) * (y_ - p.y_); return sqrt(distance); } #endif // _POINT_H_