title: Singleton object using unique_ptr
body: <p>I have the below CPP source code for creating a Singleton Object of a class using unique_ptr:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  class A
  {
  
  public:
      std::unique_ptr&lt;A&gt; getInstance(int log);
      ~A();
  
  private:
      static bool instanceFlag;
      static std::unique_ptr&lt;A&gt; single;
      A(int log);
      int mLog;
  };
  
  bool A::instanceFlag = false;
  std::unique_ptr&lt;A&gt; A::single = NULL;
  
  std::unique_ptr&lt;A&gt; A::getInstance(int log)
  {
      if(!instanceFlag)
      {
          //single = std::make_unique&lt;A&gt;(log);
          single = std::unique_ptr&lt;A&gt;(new A(log));
          instanceFlag = true;
          return std::move(single);
      }
      else
      {
          return std::move(single);
      }
  }
  
  A::A(int log) :
      mLog(log)
  {
  
      std::cout &lt;&lt; "Called A cons" &lt;&lt; std::flush &lt;&lt; std::endl;
  }
  
  int main()
  {
  std::unique_ptr&lt;A&gt; mA = A::getInstance(5);
  }
  </code></pre>
  
  <p>But when I compile the code I get below error:</p>
  
  <pre><code>$ c++ -std=c++11 try2.cpp
  try2.cpp: In function 'int main()':
  try2.cpp:45:41: error: cannot call member function 'std::unique_ptr&lt;A&gt; A::getInstance(int)' without object
   std::unique_ptr&lt;A&gt; mA = A::getInstance(5);
                                           ^
  </code></pre>
  
  <p>However I have exactly the same format of code in my project I get an error :</p>
  
  <pre><code>Source code Line 39: single = std::make_unique&lt;A&gt;(log);
  </code></pre>
  
  <p>Compilation error:</p>
  
  <pre><code>39:   required from here
  
  single = std::make_unique&lt;A&gt;(log);
  
  error: A(int log)' is private
   A::A(int log) :
    ^
  </code></pre>