Home > Back-end >  Questions about a class initialization, ask for help!
Questions about a class initialization, ask for help!

Time:04-05

Directly on the image,



Why inside the constructor of the Line, I would like to provide the default parameter values for aa and bb, there will be an error?
To solve the,

CodePudding user response:

No such written
Or
Point a={0, 0};
Or

Point a=Point (0, 0);

CodePudding user response:

A class object is the Point b, so in Line class initializes the a, b, use the following format, for your reference:
 class Line {

Point a, b;
Public:
//Line () {a, b; }
The Line (int aa=0, int bb=0) : a (aa and bb) and b (aa and bb)
{
//a.s etPoint (aa and bb);//the two sentences can omit
//b.s etPoint (aa and bb);
}
Void showPoint ()
{
A.s howPoint ();
B.s howPoint ();
}

The Line (Line & amp; L) {}
~ the Line ();
};

CodePudding user response:

The copy constructor in the Line:
 Line (Line & amp; L) 
{
A.s etPoint (L.A.G etx (), L.A.G ety ());
B.s etPoint (L.B.G etx (), L.B.G ety ());
}
  • Related