How to specify the size of a class array ?

PaulS:

String is telling us that kind of functionality is not without problems

The problem is that String instances go out of scope, triggering the destructor which calls delete which calls free(), which has a bug.

By not allowing the array to shrink, you avoid those problems.

What about growing the array ? Is it safe ?
That would happen when the user would call addBoard() more times than the available slots in the array.

PaulS:

This would be acceptable if the class was only used to declare global variables. In fact, I'd find using such kind of classes to declare local variables strange.

What kind of boards does your class refer to? Are local instances of them reasonable? For instance, Serial is an instance of the HardwareSerial class. There is only one of them, so having anything other than a global instance doesn't make sense. Does your board differ?

Sorry, I should have called them "items" :slight_smile: It was just an example. They could be anything from a byte to user-defined objects.
But yes, the use case I have in mind is about using the class to declare global variables only.