Looped function calling not looping correctly! (C++)
<p>I am doing a homework for my Systems Programming course.
I have to implement a University simulation.
I have a Course abstract class, and child class of it ComputerScienceCourse (and a bunch of other child classes that don't affect what I'm going to ask).
and I have a Student abstract class, and child class of it ComputerScienceStudent (and a bunch of other child classes that don't affect what I'm going to ask).
In the ComputerScienceCourse child class there is a function:</p>

<pre><code>void teach(){
 for(i = all students that take this course [stored in a vector of pointers to Student objects, which is a member field of the CSCourse child class, called students]){
  this-&gt;students.at(i)-&gt;study(*this);
 }
}
</code></pre>

<p>This function calls study function for all students that have taken this class. The function is a member function of child class CSStudent</p>

<pre><code>void study(Course &amp;c){
 if(this-&gt;failedclass){
  c.removeStudent(this)
 }
}
</code></pre>

<p>Now when I check the output, the loop in the teach function does not call the study function for all the students within.
For example, if I have 4 students doing this course, sometimes it would call the study function of only the first three, sometimes it calls the function for the first and the last student... varies.
What could be causing the for loop to not call ALL students study functions?!
Here's the full code for the teach function:</p>

<pre><code>    for(unsigned int i=0; i&lt;this-&gt;studentMembers.size(); i++){

    this-&gt;studentMembers.at(i)-&gt;study(*this);

}
</code></pre>
