smart pointers and when they destruct the object they point to
<p>I wish to use a smart pointer to an object that will be accessed by quite a few different objects. Therefore i don't want to destruct it until all the pointers are released to it. The smart pointer will point to an object that instantiates a couple objects, which instantiate a couple objects, and so on, so that you can access all the individual System objects through this one pointer. However, let's say that i create the smart pointer in main as <code>std::shared_ptr&lt;System&gt; object(new System);</code> and then let's say i have another object that all other entities derive from which has a static std::shared_ptr that i set equal to object above. The static declaration means that it's managed by the compiler and not on a per instance basis. So let's say that all the objects that derive from the base class use this static pointer to access the System object. WHEN is this smart pointer destructed if ever? I need this pointer to be destructed before the one in main, who's destruction should drop the reference count to 0, destroying the object pointed to by it. So my question is, when is a statically declared std::shared_ptr destructed in the scheme of things. Or even if a pointer were declared globally and used all over, when would this object be destructed?</p>

<p>the base class would look something like this:</p>

<pre><code>class Base
{
public:
    static shared_ptr&lt;System&gt; m_System;
};

int main()
{
    std::shared_ptr&lt;System&gt; system(new System);
    Base::m_System = system;

    /*
        other stuff
    */ 
    return 0;
}
</code></pre>

<p>also another thing that someone could help me with, i'm not very good with const-ness, and i would like for that static pointer to be a constant that cannot be changed by the derived classes. But then if it's const i can't initialize it like i did in main, right? so how would i go about declaring it so that it is const, but i can still set it equal to a pointer initially like this.</p>
