#include<iostream>
using namespace std;
class CCount
{
private:
int m_nCount;
public:
CCount(int count):m_nCount(count){}
friend ostream& operator << (ostream& out , const CCount& s);
friend istream& operator >> (istream& in , CCount& s);
public:
CCount& operator ++();
CCount& operator --();
CCount operator ++(int);
CCount operator --(int);
};
CCount& CCount::operator ++()
{
m_nCount += 2;
return *this;
}
CCount& CCount::operator --()
{
m_nCount -= 2;
return *this;
}
CCount CCount::operator ++(int)
{
CCount r(*this);
(this->m_nCount) += 2;
return r;
}
CCount CCount::operator --(int)
{
CCount r(*this);
(this->m_nCount) -= 2;
return r;
}
ostream& operator << (ostream& out , const CCount& s)
{
out << s.m_nCount;
return out;
}
istream& operator >> (istream& in , CCount& s)
{
int i ;
in >> i;
if(in)
{
s.m_nCount = i;
}
else
{
s = CCount(0);
}
return in;
}
int main()
{
CCount c(0);
cin>>c;
//c++;
cout<<(c++);
return 0;
}
using namespace std;
class CCount
{
private:
int m_nCount;
public:
CCount(int count):m_nCount(count){}
friend ostream& operator << (ostream& out , const CCount& s);
friend istream& operator >> (istream& in , CCount& s);
public:
CCount& operator ++();
CCount& operator --();
CCount operator ++(int);
CCount operator --(int);
};
CCount& CCount::operator ++()
{
m_nCount += 2;
return *this;
}
CCount& CCount::operator --()
{
m_nCount -= 2;
return *this;
}
CCount CCount::operator ++(int)
{
CCount r(*this);
(this->m_nCount) += 2;
return r;
}
CCount CCount::operator --(int)
{
CCount r(*this);
(this->m_nCount) -= 2;
return r;
}
ostream& operator << (ostream& out , const CCount& s)
{
out << s.m_nCount;
return out;
}
istream& operator >> (istream& in , CCount& s)
{
int i ;
in >> i;
if(in)
{
s.m_nCount = i;
}
else
{
s = CCount(0);
}
return in;
}
int main()
{
CCount c(0);
cin>>c;
//c++;
cout<<(c++);
return 0;
}
转载于:https://blog.51cto.com/lovekiky2006/93910