I have a hw project and I need to write my own reverse iterator. The problem is i don't know for sure if I'm starting off ok. Here is the code I have so far and a simple test in main keeps giving me an error stating no parameter's for template if I initialize like so:
main() {
vector<int> v;
vector<int>::iterator it;
my_reverse_iterator p(it);
}
BUT when i initialize differently i get errors such as:
main() {
vector<int> v;
vector<int>::iterator it;
my_reverse_iterator <vector<int> > p(it);
}
it gives me a bunch of errors stating:
Anachronism: using iterator_traits as a template without a declaration.
ERROR: iterator_traits is not defined.
Here is the code I have so far:
#include<iostream>
#include<iterator>
#include<vector>
using namespace std;
template <class Iter>
class my_reverse_iterator/*:public iterator<
typename iterator_traits<Iter>::iterator_category,
typename iterator_traits<Iter>::value_type,
typename iterator_traits<Iter>::difference_type,
typename iterator_traits<Iter>::pointer,
typename iterator_traits<Iter>::reference>
*/
{
private:
Iter p;
public:
typedef typename iterator_traits<Iter>::iterator_category iter_cat;
typedef typename iterator_traits<Iter>::value_type val_type;
typedef typename iterator_traits<Iter>::difference_type diff_type;
typedef typename iterator_traits<Iter>::pointer ptr;
typedef typename iterator_traits<Iter>::reference ref;
public:
typedef Iter iterator_type;
typedef my_reverse_iterator<Iter> self;
my_reverse_iterator() {}
explicit my_reverse_iterator(iterator_type i):p(i) {}
/*
~my_reverse_iterator() {}
.... base() { return p; }
// prefix
.... operator++()
{
--p;
return *this;
}
// postfix
.... operator++(int i)
{
}
// prefix
.... operator--()
{
++p;
return *this;
}
// postfix
.... operator--(int i)
{
}
// binary +
.... operator+(int i)
{
for ( int j = 0; j < i; j++)
--p;
return *this;
}
// binary -
.... operator-(int i)
{
for ( int j = 0; j < i; j++)
++p;
return *this;
}
// +=
.... operator+=(int i)
{
}
// -=
....operator-=(int i)
{
}
// *
typename iterator_traits<Iter>::value_type operator*() { return *p; }
// ->
typename iterator_traits<Iter>::value_type operator->()
{
return ;
}
// []
.... operator[]()
{
}
*/
};
main()
{
vector<int> v;
vector<int>::iterator it;
// it = v.begin();
my_reverse_iterator<vector<int> > p(it);
}
What am I doing wrong??
Thanks In Advance,