for( std::vector<OrderData>::iterator itr = m_inProcessOrders.begin(); itr != m_inProcessOrders.end(); ++itr )
since m_inProcessOrders is not a basic integer loop, I'm not sure what ++itr is actually adding to.
You can picture the vector iterator as the pointer to its array. An array is a contiguous block of memory, and exact space of memory it takes is: Number of elements, times the Size of the individual element, such as char (1 byte), int (4 bytes), and so on. The pointer to an array references the first element, and as you increment the pointer, it then references the next element of that array, whose address offset will depend on the size of the individual element.
There is no builtin way (of C/++) to stop iterating at the end of array if we use pointer. Therefore the STL vector class provides the end pointer to help you iterate through its contents. The three for loop statements are:
- Give me the begin-of-array pointer to work with this vector.
- Until our pointer compares the same as the end-of-array pointer,
- Increment it. (points to the next element on that array)
This is the standard way to iterate through vectors. Although the iterators are confusing at first sight, you'll praise this design as it adheres to the pointer arithmetic (this term describes the ability to increment, decrement, and compare two pointers as we work with arrays).
Secondly, when you dereference your pointer, written as *ptr, it lends out the value of the element at that address, whether as an L-value or R-value; that is, you can both assign the element some value if you use *ptr on the left side of an assignment operator (equal sign, =) and otherwise read the value if you use *ptr on the right side.
Thirdly, the dereferencing operator * takes lower precedence than member access operators, which are the dot (.) and the arrow (->). Thus you have to write (*ptr) when you intend to call some member function of that referenced element (can be a class object/instance, or even a pointer to them, if they are not stored in-line on the vector but in somewhere else), or else the member-access operators are first resolved, then the dereference asterisk at last, which only makes sense, of course, when the innermost member accessed is a pointer. Cf.
https://en.cppreference.com/w/cpp/language/operator_precedence
PS. Writing (*ptr).something is the same as writing ptr->something. The arrow operator existed for this exact purpose. It is the member-access operator for a pointer variable. Thus the second line in the block:
(*itr).eOrderType = NO_ORDER;
can be easily rewritten as
itr->eOrderType = NO_ORDER;