@cipermagi, back() returns the last element, end() returns one past the last element.
Otherwise, in your class just set a pointer to the last element in your array, and then increment it by one? Also, itr-- doesn't return one past the last element, it returns the last. You would have to use --itr.
@ascii: The reason that I suggested using back() is because it appears that the point of putting it at end() and then immediately pushing it towards the front by one is to...return the last element.
I know that vec.back() will do the job. But in this assignment we are going to write whole MyVec class, including every member function(begin(), end(),back()....). In other words, if you are the person who writes STL end() function, how will you write it?
Assuming all the values in your class are stored in an array (which makes sense), I would set a pointer to the last element in the array, and increment it by one. Then return the pointer.
Ok if you check what back() and end() of std::vector returns you get:
back():
A reference to the last element in the vector.
Unlike member vector::end, which returns an iterator just past this element, this function returns a direct reference.
end()
An iterator to the element past the end of the sequence.
Notice that unlike member vector::back, which returns a reference to the element preceding this one, this function returns a random access iterator.
Also I don't think end() returns NULL at some point.
What ever implementation you are using just make sure that with end() you return an iterator (in your case a random access pointer as you want vector API implemented) on past the last valid element of your vector. That means you must make sure operator[], ++, or pointers arithmetic all points to the same element.
Putting your values it in an array is probably the simplest to do.
I would imagine that your internal iterator class stores a pointer? I would then just return an iterator with its pointer set to one past the last element.
EDIT:
Note: vec.end(); should not return a NULL value. It should return an iterator object that indicates one past the last element, however you choose to represent that internally..