/**********************************************************************
* Main.cpp
* compiler:gcc,vs,vc6.0 Win32
* AUTHOR:WK
* TIME:2015 3 29
************************************************************************/
#include <iostream>
using namespace Std;
Class Coord
{
Public
Coord (int a=0,int b=0);
Coord (const Coord &p);
~coord ();
void print ();
int Getx ();
int gety ();
Private
int x, y;
};
void Coord::p rint ()
{
cout<<x<< "<<y<< ' \ n ';
}
int Coord::getx ()
{
return x;
}
int Coord::gety ()
{
return y;
}
Coord::coord (int a,int b)
{
X=a;
Y=b;
cout<< "Here just to verify that the constructor is running \ n";
}
Coord::~coord ()
{
cout<< "Here just to verify that the destructor is running \ n";
}
Coord::coord (const Coord &p)
{
x=p.x;
Y=P.Y;
cout<< "Here just to verify that the copy constructor is running \ n";
}
Common functions
Coord Fun (Coord p)
{
cout<< "Here just to verify that the fun () function has run \ n";//5. Print out
int A, B;
A=p.getx (+10);
B=p.gety (+20);
Coord R (A, b);//6. CallCustom ConstructorsAllocates memory to and initializes data members of object R
return R; 7. Call the value of R hereCustom Copy ConstructorsThe Nameless function assigned to the system is used to return
}
8. Call when exiting the fun () functionCustom destructorRelease formal parameter P
9. Function callCustom destructorReleasing objects defined in the function body R
10. CallCustom destructorFrees a nameless object generated by the system itself
int main ()
{
Coord P1 (30,40);//1. CallingCustom ConstructorsAllocates memory to and initializes the data member of the object P1
Coord P2; 2. CallCustomizing default constructorsAssigning memory to an object P2 data member and initializing it to a default value
Coord P3 (p1); 3. CallCustom Copy ConstructorsInitialize P3 with P1 and allocate memory to P3 object data members
P2=fun (p3); 4. Enter the fun () function to first call the argument P3 objectCustom Copy ConstructorsInitialize the formal parameters of fun ()
Here P2 accepted the value returned by the Nameless object.
P2.print ();//11. Output
return 0;
}//exits the main () function and then, in turn, invokes the custom destructor to release the P3,P2,P1 separately.
Thinking about a program 5 (c + + various function calls)