define itetrator for user defined type
The following piece of code uses iterator, but i am not able to understand why it is correct.
According to
http://en.cppreference.com/w/cpp/iterator/iterator , iterator it itself a class. So, what is the code below trying to do?
Note : the code is for implementing vector class.
The related line number is
7 and 24
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
template <class T>
class Vector
{
public:
// what is this??
typedef T* iterator;
Vector();
Vector(unsigned int size);
Vector(unsigned int size, const T & initial_value); //why
Vector(const Vector<T> & v); // why
~Vector();
T & back();
void push_back(const T & value);
void pop_back();
private:
unsigned int my_size;
unsigned int my_capacity;
T * buffer; // this will be replaced to iterator buffer?
};
|
Last edited on
In C++, pointers meet all the requirements of iterators, so they can be used as iterators.
Topic archived. No new replies allowed.