Commit 5d3f03f2 authored by Hans Buchmann's avatar Hans Buchmann

const for own variables

parent 3ca182af
......@@ -14,9 +14,11 @@ class Point
Point(const Point& other); //copy constructor
~Point(); //destructor never with parameters no return value
static double distance(Point p,Point q);
double distance(const Point& other); //non static instance method
//|------------------ only read
// |------------- c++ reference
double distance(const Point& other) const; //non static instance method
//| | | only read for own variables
//| |------------- c++ reference
//|
//|------------------ only read for other
private:
double xc; //x-coordinate
double yc; //y-coordinate
......@@ -50,10 +52,11 @@ double Point::distance(Point p,Point q)
// |----|----|----|----------------private
}
double Point::distance(const Point& other)
double Point::distance(const Point& other) const
{
// other.xc=0; //error because read only
// other.yc=0;
// other.yc=0; //error because read only
// xc=0; //error because read only
return std::hypot(other.xc - xc,
other.yc - yc);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment