C++: Adding Iterator Support to our Vector Class

Channel:
Subscribers:
2,650
Published on ● Video Link: https://www.youtube.com/watch?v=JcVgwCtBYKE



Duration: 28:48
149 views
0


Today we wrote a few minor functions to our Vector class (which is fixed at a capacity of 10, unlike a normal vector which will resize its capacity upwards when it fills up), including pop_back, is_empty (a better name than .empty), clear, and most interestingly how to add iterator support to it. Pointers are iterators, so just returning a pointer to the beginning and 1+ the end of arr is all it takes to make .begin() and .end() work, which means our little vector class here works with range-based for loops.







Tags:
c++
vector
iterator
range-based for
begin
end
empty
clear
pop_back