メンバー関数、友元関数++接頭辞接尾辞
1574 ワード
#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 ;
}