iterator 模板

Jarrys 2008-11-05 08:45:33


//////这是头文件——Integer.h

#ifndef INTEGER_H
#define INTEGER_H

#include<iostream>
#include<iterator>
#include<utility>

using std::iterator;

using namespace std::rel_ops;
class Integer
:public iterator<std::random_access_iterator_tag,int,int,int*,int>
{
public:
Integer(int avg=0):x(avg){}
Integer(const Integer& y):x(y.x){}
Integer& operator =(const Integer& y)
{
if(this==&y) return *this;
x=y.x;
return *this;
}
~Integer(){}


bool operator ==(const Integer& y)const {return x==y.x;}
bool operator <(const Integer& y)const {return x<y.x;}

int operator *()const {return x;}
int operator [](int n)const {return x+n;}

Integer& operator ++()
{
x++;
return *this;
}
Integer& operator --()
{
x--;
return *this;
}
Integer operator ++(int)
{
Integer tmp(*this);
x++;
return tmp;
}
Integer operator --(int)
{
Integer tmp(*this);
x--;
return tmp;
}

Integer operator+(int n)const
{
return Integer(x+n);
}
Integer operator-(int n)const
{
return Integer(x-n);
}
protected:
int x;
};
#endif





//////这是main函数。

#include<iostream>
#include<algorithm>


#include"Integer.h"

int main()
{
Integer F1(-1);
Integer L1(10);
std::copy(F1,L1,std::ostream_iterator<int>(std::cout," "));

return 0;
}


问题出在Integer定义的头部,class Integer:public iterator<std::random_access_iterator_tag,int,int,int*,int>
iterator 这个模板怎么样,大虾指教。。
...全文
132 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jarrys 2008-11-06
  • 打赏
  • 举报
回复
大家帮忙看下啊
AlwaysSLH 2008-11-05
  • 打赏
  • 举报
回复
坐等高手
帅得不敢出门 2008-11-05
  • 打赏
  • 举报
回复
帮顶
Jarrys 2008-11-05
  • 打赏
  • 举报
回复
在看的,可以发个提示下哈,在线等。。。。

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧