#include<iostream> using namespace std; class num { private: int n; public: num(){n=1;} ~num(){} int get()const{return n;} void set(int x){n=x;} void add(){n++;} num operator++() { ++n; num t; t.set(n); return t; }
}; int main() { num i; cout<<"i:"<<i.get()<<endl; //i++; i.add(); cout<<"i:"<<i.get()<<endl; //++i; num n=++i; //num n=i.operator ++(); cout<<"i:"<<i.get()<<endl; return 0; }
#include<iostream> using namespace std; class num { private: int n; public: num(){n=1;cout<<"构造函数执行\n";} num(int i){n=i;cout<<"带参数的构造函数执行\n";} ~num(){cout<<"析构函数执行\n";} int get()const{return n;} void set(int x){n=x;} void add(){n++;} num operator++() { ++n; return num(n); }
}; int main() { num i; cout<<"i:"<<i.get()<<endl; //i++; i.add(); cout<<"i:"<<i.get()<<endl; //++i; num n=++i; //num n=i.operator ++(); cout<<"i:"<<i.get()<<endl; return 0; }