Home > Back-end >  C plus plus the constructor
C plus plus the constructor

Time:10-30

#include
#include
using namespace std;
The class Point
{
Public:
Point (double xx, double yy)
{
X=xx;
Y=yy.
};
void setvalue();
Void Getxy ();
Friend double short (Point & amp; A, Point & amp; B);
Private:
double x, y;
};
Void Point: : setvalue () {
cout<" The value of the input point x, y, the blank space key separate: ";
Cin> x;
Cin> y;
}
The void Point: : Getxy ()
{
cout <"(" & lt; }
Double short (Point & amp; A, Point & amp; B)
{
Double dx=a.x - b.x;
Double dy=a.y - b.y;
Return SQRT (dy dx + dy dx * *);
}
Int main (void)
{
Point p1, p2,
P1. The setvalue ();
P1. Getxy ();
P2. Setvalue ();
P2. Getxy ();
Double d=short (p1, p2);
cout <"Short is" & lt; return 0;
}
-- -- -- -- -- -- -- -- -- -- -- --
Why delete constructor can run the code, not delete can not input from the keyboard? Or have other problems?

CodePudding user response:

The constructor to two parameters, define the object but not take ginseng

CodePudding user response:

You override the constructor, you must call at the time of instantiation objects show, don't delete function, the constructor instead you wrote no structure, function without internal code
  • Related