class AA
{
private:
int a;
public:
AA():a(0){};
AA& operator ++()// prefix
{
cout <<"++AA"<<endl;
++a;
return *this;
}
AA operator ++(int)// suffix
{
cout <<"AA++"<<endl;
AA temp = *this;
++a;
return temp;
}
void show()
{
cout<<"int: "<<a<<endl;
}
};
int _tmain(int argc, char* argv[])
{
for (size_t i=10; i--!=0;)
{
cout<<i<<endl;// 9 8 7 6 5 4 3 2 1 0
}
AA t;
++t;
t.show();
t++;
t.show();
return 0;
}
operator++ 重载
最新推荐文章于 2023-08-07 20:58:10 发布