Stephan Born wrote:
Nicola Musatti wrote:
Within the singleton class I hold the instance with a shared_ptr. I consider this the best option, as it guarantees the correct order of destruction when a singleton depends on another one.
But I *want* it to be delete automagically...and I do not see the danger: if there is a dependent second_singleton it would hold a shared_ptr to my singleton, and singleton would not be destroyed before second_singleton is destroyed by its own. Maybe it should be made an option by using policies....but I really do not the danger.
I think we mean the same thing. The only thing I was pointing out is that my static data member that holds the pointer is a shared_ptr and not a weak_ptr. This is because I want my singleton instance to survive even if sometime during execution it isn't used by other objects, rather than be recreated each time as yours is. Cheers, Nicola Musatti