diff --git a/practical_exercises/10_day_practice/day7/一元运算符/计数器前后自增.cpp b/practical_exercises/10_day_practice/day7/一元运算符/计数器前后自增.cpp index 90d94f8..d85d885 100644 --- a/practical_exercises/10_day_practice/day7/一元运算符/计数器前后自增.cpp +++ b/practical_exercises/10_day_practice/day7/一元运算符/计数器前后自增.cpp @@ -1,4 +1,4 @@ -//һcounterԱʵּԪʵּԼ +//设计一个计数器counter,用类成员重载自增运算符实现计数器的自增,用友元重载实现计数器的自减。 #include using namespace std; class Counter{ @@ -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="<