0

Array of Class Objects vs Derived Classes (C++)

Which is more efficient for program execution and/or memory consumption? I wrote a program that currently uses a 2D array of class objects (4x5 - each dimension has a specific attribute in common). Would it be better to create 5 derived classes and use 1D arrays for the other dimension? I chose the dimension with 5 elements because I will not be adding to that particular dimension, but I may add more to the dimension with 4 elements, which would require the creation of additional derived classes.

9th Mar 2017, 6:25 PM
Daniel Davis
Daniel Davis - avatar
1 Respuesta
+ 1
For performance you want arrays over objects, in theory.
9th Mar 2017, 10:05 PM
1of3
1of3 - avatar