????1.??????????????????????????????
??????????
???????????????з????
????????????????????????????????????????????????????????????????????????????
??????????????????????????ù?????
????????????
??????????????в????????з???????????????????????????????????????????????
????????????????ж??????????????????????????????????????????????????????????
??????????????1.????????????????????????н????????????????????????????????????2.??new??????????????????????delete?????????????
??????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????á?????????????±??????
???????????????????????????????????????????
???????????β????????????ú????????βκ???ε??????
???????????????????????????????????????
??????????
????C++ Code
/*
version: 1.0
author: hellogiser
blog: http://www.cnblogs.com/hellogiser
date: 2014/9/25
*/
#include "stdafx.h"
#include <iostream>
using namespace std;
class point
{
private:
int x?? y;
public:
point(int xx = 0?? int yy = 0)
{
x = xx;
y = yy;
cout << "Constructor" << endl;
}
point(const point &p)
{
x = p.x;
y = p.y;
cout << "Copy Constructor" << endl;
}
~point()
{
cout << "Destructor" << endl;
}
int get_x()
{
return x;
}
int get_y()
{
return y;
}
};
void f(point p)
{
// copy constructor
cout << p.get_x() << "  " << p.get_y() << endl;
// destructor
}
point g()
{
point a(7?? 33); //constructor
return a; // copy constructor    temp object
}
void test()
{
point a(15?? 22); // constructor
point b(a); //(1) copy constructor
cout << b.get_x() << "  " << b.get_y() << endl; // 15 22
f(b);//  (2) copy constructor
b = g(); // (3) copy constructor
cout << b.get_x() << "  " << b.get_y() << endl; // 7  33
}
int main()
{
test();
return 0;
}
/*
Constructor
Copy Constructor
15      22
Copy Constructor
15      22
Destructor
Constructor
Copy Constructor
Destructor
Destructor
7       33
Destructor
Destructor
*/