title: Is this a correct Implemenation of the Singleton Pattern?
body: <p>The following code is my implementation of the Singleton Pattern.</p>
  
  <pre><code> #include &lt;iostream&gt;
  
  template&lt;class T&gt;
  class Uncopyable
  {
  protected:
      Uncopyable(){}
      ~Uncopyable(){}
  private:
      Uncopyable(const Uncopyable&lt;T&gt;&amp;);
      Uncopyable&amp; operator=(const Uncopyable&lt;T&gt;&amp;);
  };
  
  template &lt;class T&gt;
  class Singleton : private Uncopyable&lt;T&gt;
  {
  public:
      static T* getInstancePtr()
      {
          return instance;
      }
  protected:
      Singleton&lt;T&gt;()
      {
          if(instance == 0)
          {
              instance = new T();
          }
      };
      ~Singleton&lt;T&gt;()
      {
  
      };
  private:
      static T* instance;
  };
  template&lt;class T&gt; T* Singleton&lt;T&gt;::instance = 0;
  
  class Test : public Singleton&lt;Test&gt;
  {
  public:
      Test(){};
      ~Test(){};
      inline void test() const
      {
          std::cout &lt;&lt; "Blah" &lt;&lt; std::endl;
      }
  private:
      friend class Singleton&lt;Test&gt;;
  protected:
  };
  
  int main(int argc, char* argv[])
  {
      Test* t = Test::getInstancePtr();
      Test* t2 = Test::getInstancePtr();
  
      t-&gt;test();
      t2-&gt;test();
  
      return 0;
  }
  </code></pre>
  
  <p>It works in this form, however I am uncertain as to whether it really is correct due to the constructor and destructor of the Singleton being protected as opposed to being private. If I declare them as private the code will not compile as they are not accessible to the class. Is this implementation safe to use, or is there anything I can do to improve it to ensure only one instance will be created and used. </p>
  
  <p>Thanks</p>