#include<iostream> using namespace std; class over { int i1 , i2 ,i3; public: void init(int I1=0 , int I2 =0, int I3=0); void print(); public: over operator ++();//前缀 over operator++(int);//后缀 friend over operator--(over &);//友元前缀 friend over operator--(over & , int );//友元后缀 }; void over::init(int I1 , int I2, int I3) { i1 = I1 ; i2 = I2 ; i3 = I3 ; } void over::print() { cout<<"i1 = "<<i1<<" , i2 ="<<i2<<" , i3 ="<<i3<<endl; } over over::operator++()//成员函数-前缀 { ++i1 ; ++i2 ; ++i3 ; return *this ; } over over::operator++(int )//成员函数-后缀 { i1++; i2++; i3++; return *this ; } over operator--(over & op)//友元 前缀 { --op.i1 ; --op.i2 ; --op.i3 ; return op ; } over operator--(over & op , int )//友元后缀 { op.i1-- ; op.i2-- ; op.i3-- ; return op ; } int main() { over ob1 , ob2 , ob3 , ob4 ; ob1.init(); ob2.init(7,7,7); ob3.init(11,11,11); ob4.init(13,13,13); ++ob1 ;//隐式调用over operator++() ob2++;//隐式调用over operator++(int) --ob3;//隐式调用over operator--(over&) ob4--;//隐式调用over operator--(over& ,int) ob1.print(); ob2.print(); ob3.print(); ob4.print(); cout<<"-------------------------"<<endl; ob1.operator++();//显示调用,++ob1 ob2.operator++(0);//显示调用ob2++; operator--(ob3);//显示调用--ob3; operator--(ob4,0);//显示调用ob4--; ob1.print(); ob2.print(); ob3.print(); ob4.print(); getchar(); return 0 ; }