I am writing a code that utilizes a dynamic array to store objects of a class with various functions and variables. Let's say that I wanted to make a loop to call a function for each object in the array. How would I do that? I cannot just say something like object1.function() because i need to be able to call the function from each object in the array. I have also tried something like array.function(), but this always ends up in getting wrong values for the member variables in the function. There must be something that I have yet to learn which will save this code.
Here is a code fragment just to help demonstrate what I'm talking of.
1 2 3 4 5 6
className array = object1; //array = object2 and so on...
for (int i = 0; i < 5; i++)
object1.function(); //Will only call function for object1 but with correct values
array[i].function(); //Variables in the function get wrong values