I have been reading C ++ for half a month. I see a piece of code.
checkedptr& checkedptr::operator++(int){checkedptr ret(*this);++*this;return ret;}
The Code is as follows:
#include<iostream>using namespace std;class checkedptr{public:checkedptr(int *b,int *e):beg(b),end(e),curr(b){}checkedptr& operator++();checkedptr& operator++(int);friend ostream& operator<<(ostream& out,const checkedptr &c);~checkedptr(){}private:int* beg;int* end;int* curr;};checkedptr& checkedptr::operator++(){if(curr==beg)throw out_of_range("increment past the end of checkedptr");++curr;return *this;}checkedptr& checkedptr::operator++(int){checkedptr ret(*this);++*this;return ret;}ostream& operator<<(ostream& out,const checkedptr &c){out<<*(c.curr);return out;}int main(){int arr[]={1,2,3,4,5,6,7,8,9};checkedptr parr(arr,arr+9);cout<<"++a:"<<++parr;checkedptr par(arr+4,arr+9);cout<<"a++:"<<++par;return 0;}
The compilation result is correct and an error occurs during running.
Thank you for your guidance.