We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents bed5771 + 374867b commit 75cef2cCopy full SHA for 75cef2c
practical_exercises/10_day_practice/day7/一元运算符/计数器前后自增.cpp
@@ -1,4 +1,4 @@
1
-//设计一个计数器counter,用类成员重载自增运算符实现计数器的自增,用友元重载实现计数器的自减。
+//设计一个计数器counter,用类成员重载自增运算符实现计数器的自增,用友元重载实现计数器的自减。
2
#include<iostream>
3
using namespace std;
4
class Counter{
@@ -17,16 +17,18 @@ Counter Counter::operator++(){
17
return *this;
18
}
19
Counter Counter::operator++(int){
20
+ Counter t=*this;
21
n++;
- return *this;
22
+ return t;
23
24
Counter operator--(Counter &c){
25
--c.n;
26
return c;
27
28
Counter operator--(Counter &c,int){
29
30
c.n--;
- return c;
31
32
33
void Counter::display(){
34
cout<<"counter number="<<n<<endl;
0 commit comments