Home > Back-end >  The combination of class initialization
The combination of class initialization

Time:10-02

#include
using namespace std;
Const double PI=3.14159;

The class Point
{
int x,y;
Public:
Point (int a=0, int b=0)
{
X=a;
Y=b;
}

Void SetP (int a, int b)
{
X=a;
Y=b;
}
Int getX () {return x; }
Int getY () {return y; }
};
The class Circle
{
Point p1.
Int the radius;
Public:

Circle (Point PI=Point (3, 4), int r=0) : p1 (PI), the radius (r)
{

}
Void SetCC (Point PI, int r)
{
Point p (PI);
The radius=r;
}
Void the show ();
Radius, double getArea () {return PI * * radius; }


};
Void Circle: : show ()
{
cout<& lt;" Center coordinates X="& lt; CodePudding user response:

You haven't changed it and P1, you have a good look at the scope,
Void SetCC (Point PI, int r)
{
Point p (PI);//this is temporary variables defined p1 is your data members p1, you changed to p1. The SetP (PI) getX (), PI, getY ()) it is ok to
The radius=r;
}

CodePudding user response:

Void SetCC (Point PI, int r) {
P1=(PI);
The radius=r;
}
  • Related