您的位置:首页 > 其它

请编写一个类, 使其具有整形变量i的i++以及++i的功能

2009-11-07 20:50 387 查看
#include <iostream>
using namespace std;
class Int
{
public:
Int(int i): i_data(i) {}
int operator++();
int operator++(int);
friend ostream& operator<<(ostream& os, Int vi);
private:
int i_data;
};
int Int::operator++()
{
return ++i_data;
}
int Int::operator++(int)
{
int temp;
temp = i_data++;
return temp;
}
inline ostream& operator<<(ostream& os, Int vi)
{
cout << vi.i_data;
}
int main()
{
Int I(1);
cout << I << endl;
cout << ++I << endl;
cout << I++ << endl;
cout << I << endl;
system("PAUSE");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐