C++??????????????
?????C++ ???????[ 2014/10/17 14:45:43 ] ????????C++ ??????
????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
*/
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11