[flydream@flydream InterView]$ cat Point.cpp
#include <iostream>
using namespace std;
class Point
{
public:
Point(int xx = 0, int yy = 0) { X = xx; Y = yy; }
Point(const Point &p);
int GetX() { return X; }
int GetY() { return Y; }
private:
int X, Y;
};
Point::Point(const Point &p) //�������캯�
{
X = p.X;
Y = p.Y;
cout << "Copy constructure called !" << endl;
}
void fun1(Point p)
{
cout << p.GetX() << endl;
cout << p.GetY() << endl;
}
Point fun2()
{
Point R(1,2);
return R;
}
int main(int argc, char **argv)
{
Point A(4,5);
cout << "First---------------------------" << endl;
Point B(A);
cout << "First Complete------------------" << endl;
cout << B.GetX() << endl;
cout << B.GetY() << endl;
cout << "Second---------------------------" << endl;
fun1(B);
cout << "Second Complete------------------" << endl;
cout << "Third---------------------------" << endl;
B = fun2();
cout << "Third Complete-------------------" << endl;
cout << B.GetX() << endl;
cout << B.GetY() << endl;
return 0;
}
[flydream@flydream InterView]$
[flydream@flydream InterView]$ g++ Point.cpp
./[flydream@flydream InterView]$ ./a.outFirst---------------------------
Copy constructure called !
First Complete------------------
4
5
Second---------------------------
Copy constructure called !
4
5
Second Complete------------------
Third---------------------------
Third Complete-------------------
1
2
[flydream@flydream InterView]$