Home > Back-end >  To the C program
To the C program

Time:10-12

Reading, reading the following c + + programs, annotation for each statement suggests that the role of (please paste the source code or screen shot, do not upload attachments),

#include using namespace std; The class CTest {private: int x, y; Public: CTest (int p1=0, int p2=0) {x=p1; Y=p2; } CTest (CTest & amp; P) {x=p.x; Y=p.y; } to void the Show () {cout & lt;

CodePudding user response:

#include //the header file
using namespace std;//namespace

//class name
The class CTest
{
Private:
Int x, y;//private member variables
Public:
//the constructor
CTest (int p1=0, int p2=0)
{
X=p1.//p1 assigned to x
Y=p2;//p2 assigned to y
}
//copy constructor
CTest (CTest & amp; P)
{
X=p.x;//assignment
Y=p.y;//assignment
}
//normal function, print the x, y
Void the Show ()
{
cout }
};

Int main ()
{
CTest obj1;//class variables obj1
Obj1. The Show ();//call the print function Show

CTest obj2 (2, 5);//class variables obj2
Obj2. The Show ();//call the print function Show

CTest obj3 (obj2);//class variables obj3, calls the copy constructor
Obj3. The Show ();//call the Show

return 0;
}
  • Related