重载前置自加运算符实例
#include <iostream>using namespace std;
class num
{
public:
num(){n=1;}
~num(){}
int get()const{return n;}
void add(){++n;}
void operator++(){++n;}
private:
int n;
};
int main()
{
num i;
cout<<"i:"<<'\t'<<i.get()<<endl;
i.add();
cout<<"i:"<<'\t'<<i.get()<<endl;
++i;
cout<<"i:"<<'\t'<<i.get()<<endl;
return 0;
}