Skip to content

Commit

Permalink
Update 计数器前后自增.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Falling-in-W-sweetty committed Aug 14, 2022
1 parent 9f58fef commit 374867b
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//设计一个计数器counter,用类成员重载自增运算符实现计数器的自增,用友元重载实现计数器的自减。
//设计一个计数器counter,用类成员重载自增运算符实现计数器的自增,用友元重载实现计数器的自减。
#include<iostream>
using namespace std;
class Counter{
Expand All @@ -17,16 +17,18 @@ Counter Counter::operator++(){
return *this;
}
Counter Counter::operator++(int){
Counter t=*this;
n++;
return *this;
return t;
}
Counter operator--(Counter &c){
--c.n;
return c;
}
Counter operator--(Counter &c,int){
Counter t=*this;
c.n--;
return c;
return t;
}
void Counter::display(){
cout<<"counter number="<<n<<endl;
Expand Down

0 comments on commit 374867b

Please sign in to comment.