How to Create OOP Instance Name on the Fly?

Hi, I'm using Object Oriented Programming and some of the classes have a lot of instances. I'm using a touch screen and when making adjustments so it needs to know which instance of the class to call so the proper schedule (in this case) is called.

For classes with say 10 instances, I use a switch case using an ID so it can find the correct instance to change. For example.

        switch (ID)
          case 1: Sch1.changeHour(0); Sch1.printHour(298, 161); break;
          case 2: Sch2.changeHour(0); Sch2.printHour(298, 161); break;
          case 3: Sch3.changeHour(0); Sch3.printHour(298, 161); break;
          case 4: Sch4.changeHour(0); Sch4.printHour(298, 161); break;
          case 5: Sch5.changeHour(0); Sch5.printHour(298, 161); break;

This works well but now I have a class with 80 instances and will grow to 100 so I'm wondering if theres a more efficient way.

I'm wondering if I can update the instance name using a variable somehow?

I tried this, of course it doesn't work but this is what I'm trying to accomplish. Any ideas?

String instanceName;
instanceName = "Sch4";
instanceName.changeHour(0);   // this would actually be Sch4.changeHour(0); as the string is set to "Sch4"
instanceName.printHour(298, 161);   // this would actually be Sch4.printHour(298, 161); as the string is set to "Sch4"

Normally you would use an array of (in this case) Schedule objects.

If it needs to grow dynamically, then you could use malloc() and/or realloc() to resize the array, or you would use a structure such as a linked list. But this is very tricky to get right. Google "memory leak".

In the arduino environment, where space is very tight, you would usually use a static array that's big enough for what a user might want to do, and consequently have a maximum limit to how many schedule items a user can have.

Thanks for your reply. I don't need dynamic, the schedules are set in stone, it'll be 80 but for other schedules that I can use the same class brings it to 100 or so.

I didn't think of an array because I would think a size of 100 is too large?

I assume using a long switch case would use less memory but more space?

Any idea how much memory an array of 100 might use?

I didn't think of an array because I would think a size of 100 is too large?

100 objects in 100 instance variables takes no less space that 100 objects in an array.