📄 ex4-1-3.cpp
字号:
#include <iostream>
using namespace std;
class CCounter
{
private:
unsigned int m_nCounter;
public:
CCounter() { m_nCounter = 0; }
CCounter(CCounter& c) { m_nCounter = c.m_nCounter; }
~CCounter() {}
friend CCounter& operator++(CCounter& c);
friend const CCounter operator++(CCounter& c, int);
unsigned operator()()
{
return m_nCounter;
}
};
CCounter& operator++(CCounter& c)
{
c.m_nCounter++;
return c;
}
const CCounter operator++(CCounter& c, int)
{
CCounter before(c);
c.m_nCounter++;
return before;
}
void main(void)
{
CCounter c, s;
cout << "First of all, c=" << c() << ", s=" << s() << endl;
s = ++c;
cout << "After s=++c, c=" << c() << ", s=" << s() << endl;
s = c++;
cout << "After s=c++, c=" << c() << ", s=" << s() << endl;
++ ++c;
cout << c();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -