Hi, I know it may sound weird.
But I'm doing a class and I want only 10 objects can be created. So I wanted to prevent the creation of the object or destroyed after being created.
Thank you very much
I think the trick is to make the constructor private so only a member function can construct new objects. Then you can write a class static function to return a pointer to one of the ten objects or a null pointer if all the objects are in use.
Make the constructor private.
Either provide a static factory method that return NULL if the object cannot be constructed, or create a static array of 10 and only 10 objects in the class.
But … why would you want to do this in a microcontroller? I mean, lets say there's a bit of code somewhere that wants that 11th object. What's it supposed to do when it can't get it? Pop up an error window?
Sorry about delayed answer. Many thanks for the help, I declared the constructor as private and I created a static method to achieve it. It works very well.
I'm working on ESP8266, I have enough memory and speed.
I want to make a flexible firmware, I create the objects according to the setting from a json file and thus to be able to configure its operation.