Commit 311962b3 authored by Hans Buchmann's avatar Hans Buchmann

not point method distance

acesses private parts
parent 2bae2e3d
......@@ -32,66 +32,22 @@ Point::~Point()
}
/*
{
{
Point p(1,1);
}
Point q(2,2);
Point r(3,3);
}
constructor Point 1,1
destructor Point 1,1
constructor Point 2,2
constructor Point 3,3
destructor Point 3,3
destructor Point 2,2
*/
/*
{
{
Point p(1,1);
{
Point q(2,2);
{
Point r(3,3);
}
}
}
constructor Point 1,1
constructor Point 2,2
constructor Point 3,3
destructor Point 3,3
destructor Point 2,2
destructor Point 1,1
geo2d-bb.cc:36:22: error: double Point::xc is private within this context
*/
/*
// distance not in class Point
double distance(Point p,Point q)
{
Point p(1,1); //instance of class Point defined and initalized constructor
Point q(2,2);
Point r(3,3);
return std::hypot(q.xc-p.xc,q.yc-p.yc); //<---- error
// |----|----|----|----------------private
}
constructor Point 1,1
constructor Point 2,2
constructor Point 3,3
destructor Point 3,3
destructor Point 2,2
destructor Point 1,1
*/
//--------------------------- use case
int main(int argc,char** args)
{
Point p(1,1); //constructor p
{
Point q(2,2); //constructor q
{
Point r(3,3); //constructor r
} //destructor r
}//destructor q
Point p(5, 7);
Point q(8,11);
//distance p -> q sqrt(3*3 + 4*4)=sqrt(25)=5
auto d=distance(p,q);
std::cout<<"d="<<d<<"\n";
return 0;
} //destructor p
}
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