#include <iostream>
using namespace std;
class Sample
{
protected:
int x;
public:
Sample() { x=0; }
Sample(int val) { x=val; }
void operator++() { x++; }
};
class Derived:public Sample
{
int y;
public:
Derived():Sample(){ y=0; }
Derived(int val1,int val2):Sample(val1){ y=val2; }
void operator--(int){ x--;y--;} //这才是d--的原型,--d的原型是&operator--()
void operator++(int){ x++;y++;}
void disp()
{
cout<<"x="<< x <<" y=" << y << endl;
}
};
void main ()
{
Derived d(3,5);
d.disp();
d++;
d.disp ();
d--;
d--;
d.disp();
}
using namespace std;
class Sample
{
protected:
int x;
public:
Sample() { x=0; }
Sample(int val) { x=val; }
void operator++() { x++; }
};
class Derived:public Sample
{
int y;
public:
Derived():Sample(){ y=0; }
Derived(int val1,int val2):Sample(val1){ y=val2; }
void operator--(int){ x--;y--;} //这才是d--的原型,--d的原型是&operator--()
void operator++(int){ x++;y++;}
void disp()
{
cout<<"x="<< x <<" y=" << y << endl;
}
};
void main ()
{
Derived d(3,5);
d.disp();
d++;
d.disp ();
d--;
d--;
d.disp();
}