forked from mrchuanxu/RegularNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview.cpp
59 lines (52 loc) · 1.1 KB
/
review.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <string>
using namespace std;
extern int i;
int ival = 1024;
int &refVal = ival;
int *p = &ival;
int *&r = p;
const int ci = 42;
const int &r1 = ival;
class A{
private:
int value;
public:
A(int n){value = n;}
A(const A& other){value = other.value;}
void Print(){ cout << value << endl;}
};
class CMyString{
public:
CMyString(char* pData = nullptr);
CMyString(const CMyString& str);
~CMyString(void);
CMyString& operator=(const CMyString&);
private:
char* m_pData;
};
// 初级程序员
// CMyString& CMyString::operator=(const CMyString& mptr){
// if(this == &mptr)
// return *this;
// delete []m_pData;
// m_pData = nullptr;
// m_pData = new char[strlen(mptr.m_pData)+1];
// strcpy(m_pData,mptr.m_pData);
// return *this;
// }
// 高级程序员
CMyString& CMyString::operator=(const CMyString& mptr){
if(this!=&mptr){
CMyString strTmp(mptr);
char* stmp = strTmp.m_pData;
strTmp.m_pData = m_pData;
m_pData = stmp;
}
return *this;
}
int main(){
cout << refVal << endl;
cout << r1 << endl;
return 0;
}