64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class B
{
int value;
public:
B()
{
static int i=0;
value=++i;
}
B& operator ++()
{
value++;
return *this;
}
const B operator ++(int)
{
B temp =*this;
++(*this);
return temp;
}
friend void main();
B f()
{
B temp=*this;
return temp;
}
};
void main()
{
B a1,b2,c3,d4; //a1=1 b2=2 c3=3 d4=4
b2=++a1; //a1=2 b2=2
a1.operator ++()=c3; //c3=3 a1=3
c3=a1++; //c3 =3 a1=4
d4.f()=b2;
//a1=4 b2=2 c3=3 d4 =4
cout <<a1.value <<endl <<b2.value <<endl <<c3.value <<endl <<d4.value <<endl;
}