-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethord1.cpp
65 lines (53 loc) · 1.13 KB
/
methord1.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
60
61
62
63
64
65
//ostream& operator<<(ostream& out, ppp p)
//ppp& operator++(int)
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iomanip>
using namespace std;
class ppp {
friend ostream& operator<<(ostream& out, ppp p);
public:
int a;
int b;
ppp() {
a = 0;
b = 0;
}
ppp(int a, int b) {
this->a = a;
this->b = b;
}
ppp& operator++();
ppp& operator++(int);
};
ppp& ppp::operator++() {
this->a++;
this->b++;
return *this;
}
ppp& ppp::operator++(int) {
ppp* temp = new ppp();
*temp = *this;
this->a++;//记录当前本身的值,然后让本身的值加1,但是返回的是以前的值,达到先返回后++;
this->b++;
return *temp;
}
ostream& operator<<(ostream& out, ppp p) {
out << p.a<<" " << p.b;
return out;
}
void testwork(){
ppp p1(1, 10);
cout << p1++ << endl;
cout << p1 << endl;
ppp p2(1, 10);
cout << ++p2 << endl;
cout << p2 << endl;
}
int main(){
testwork();
return EXIT_SUCCESS;
}