Commit 3ca182af authored by Hans Buchmann's avatar Hans Buchmann

the keyword const for parameter

parent f75afecc
......@@ -14,8 +14,9 @@ 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(Point& other); //non static instance method
// |------------- c++ reference
double distance(const Point& other); //non static instance method
//|------------------ only read
// |------------- c++ reference
private:
double xc; //x-coordinate
double yc; //y-coordinate
......@@ -49,12 +50,10 @@ double Point::distance(Point p,Point q)
// |----|----|----|----------------private
}
double Point::distance(Point& other)
double Point::distance(const Point& other)
{
/* hack
other.xc=0; like by value but in fact by reference
other.yc=0;
*/
// other.xc=0; //error because read only
// other.yc=0;
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