#include <iostream>
using namespace std; class counter{ public: counter() { v=0; } counter operator ++(); //前置 counter operator ++(int );//后置 void print() { cout<<v<<endl; } private: unsigned v; };
counter counter::operator ++() //前置 { v++; return *this; }
counter counter::operator ++(int) //后置 { counter t; t.v = v++; return t; }
void main() { counter c; for(int i=0; i<8; i++)c++; c.print();for(i=0; i<8; i++)++c; c.print(); }
|