// this code is for implementing vector in C++
template <class T>
class Vector
{
public:
Vector();
~Vector();
iterator begin(); // return type is iterator
iterator end();
private:
unsignedint my_size;
unsignedint my_capacity;
T * buffer;
};
template<class T>
typename Vector<T>::iterator Vector<T>::begin() // return_type of begin() of buffer
{
return buffer;
}
Now, as in typename Vector<T>::iterator Vector<T>::begin(), the return type is an iterator of type Vector<T>::iterator. How should i declare/defineiterator in the class Vector<T>?
The class is generic, so how will the iterator be defined?
For your particular implementation, you can use plain pointers as iterators instead of defining your own iterator classes. If there is a specific reason to define your own iterator classes, then I can't see it from the code you posted.
Add this anywhere in your class
If you just want your container to work with range based for loops aka for (T object : vector) then you just need this: using iterator = T*;
If you want practice writing your own iterator, do what LB has just suggested