return 0; }
//程序员面试宝典const题3
#include <iostream>
#include <iomanip>
using namespace std;
class C
{
public:
C(int i):m_Count(i){}
int incr()const
{
return ++m_Count;
}
int decr()const
{
return --m_Count;
}
private:
mutable int m_Count;
};
int main(void)
{
C c1(0),c2(10);
for(int tmp,i = 0; i < 10; i++)
{
tmp = c1.incr();
// cout << setw(tmp) << setfill(' ') << tmp << endl;
cout << setw(tmp) << tmp << endl;
tmp = c2.decr();
cout << setw(tmp) << setfill(' ') << tmp << endl;
}
return 0;
}
结果:
1
9
2
8
3
7
4
6
5
5
6
4
7
3
8
2
9
1
10
0