How to iterate through a list of objects in C++?
You’re close. Note that you can define it inside the for loop: And if you are using C++11 then you can use a range-based for loop instead: Here auto automatically deduces the correct type. You could have written Student const& i instead.