I'm new to c++ (and SO) so sorry if this is obvious.
I've started using temporary arrays in my code to cut down on repetition and to make it easier to do the same thing to multiple objects. So instead of:
MyObject obj1, obj2, obj3, obj4;
obj1.doSomming(arg);
obj2.doSomming(arg);
obj3.doSomming(arg);
obj4.doSomming(arg);
I'm doing:
MyObject obj1, obj2, obj3, obj4;
MyObject* objs[] = {&obj1, &obj2, &obj3, &obj4};
for (int i = 0; i !=4; ++i)
objs[i]->doSomming(arg);
Is this detrimental to performance? Like, does it cause unnecessary memory allocation? Is it good practice? Thanks.