In the first question, you should ideally use initializer lists to ensure that your pointers are valid. Not doing this means that you potentially need to always check if your pointer is valid before using it; especially if you leave it up to the calling code to call init()
On the other hand, maybe you canβt do this if they can only be installed by calling a pure virtual one, in which case you will have to use the init() method.
Upon initialization, I would think that you can either catch, or throw, or simply not catch. In any case, it would be preferable if the caller would throw a memory allocation exception.
I see why you want to try to eliminate memory allocation when calling init() on one of your objects. The approach here may be to replace a stub object that always calls init()
I donβt understand why you want to check the release of shared pointers (possibly raw pointers). Of course, the point with common pointers is that although you can refer to a common pointer that you, by definition, share it so that it is not destroyed yet.
Perhaps you can check the number of links or specify your selected object and (when destroyed) clear the semaphore that your test can control. Did I miss something?
source share