Call function with same name for every object
Jul 9, 2016 at 7:58pm UTC
I have about 12 classes, with a variable number of objects each.
they all have a function called update()
is there a way to call update for every class without writing it all out manually like this:
1 2 3
objectone.update();
objecttwo.update();
...
I would prefer to do something like this:
1 2 3 4
for (const objects& object : everyobject)
{
object.update();
}
Jul 9, 2016 at 8:44pm UTC
Hi,
You might want to show your code to prove that manually calling update() for a large number of objects is long & problematic. After that, we will analyze your code and give you the best approach to suit your needs.
Jul 9, 2016 at 11:38pm UTC
s there a way to call update for every class without writing it all out manually like this:
Presumably you mean "every
object ."
Are these objects in a container? Do the classes share a common base?
Jul 10, 2016 at 1:05am UTC
Put them in a container, iterate through the container, and call update() in each iteration.
Topic archived. No new replies allowed.