Hello! There is a class:

Class MyClass {...}; 

make ten copies of it

 MyClass _my_new_class1; MyClass _my_new_class2;... MyClass _my_new_class10; 

Can you please tell me how to loop through all the instances?

  • 3
    > MyClass _my_new_class2; > ...> MyClass _my_new_class10; See the Chinese code - karmadro4

3 answers 3

Put in an array and sort through the array.

    • declare an array of class instances
    • create a list as a static member of this class and in the constructor add each instance to this list

      As already mentioned, to create an array (or any container from STL, best of all, I think the vector will work for this task) with these objects. Or create an array (container) of pointers to objects and bypass them.