title: Why can't I access the private constructor in my static function as below?
body: <p>I'm currently write a weak reference resource manager as below, and the compiler complained Manager has a private constructor.</p>
  
  <p>My question is that: why can't I access the private member function in the static function?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#ifndef TENSOR_MANAGER_H
  #define TENSOR_MANAGER_H
  
  #include &lt;memory&gt;
  #include &lt;functional&gt;
  #include &lt;map&gt;
  #include &lt;iostream&gt;
  
  template&lt;typename key_t, typename model_t&gt;
  class Manager : public std::enable_shared_from_this&lt;Manager&lt;key_t, model_t&gt; &gt; {
  public:
      using self_t = Manager&lt;key_t, model_t&gt;;
  
  public:
      static auto Create() {
          return std::make_shared&lt;self_t&gt;();
      }
  
  public:
  
      std::shared_ptr&lt;model_t&gt; GetOrAdd(const key_t &amp;&amp;key, const char *data, size_t size) {
          auto pos = m_resources.find(key);
          std::shared_ptr&lt;model_t&gt; tmp;
          if (pos != m_resources.end()) {
              tmp = pos-&gt;second.lock();
          }
          if (!tmp) {
              model_t *p = new model_t();
  
              auto deletor = std::bind(&amp;self_t::releaseItem,
                                       std::weak_ptr&lt;self_t&gt;(this-&gt;shared_from_this()),
                                       key,
                                       std::placeholders::_1);
  
              tmp = std::shared_ptr&lt;model_t&gt;(p, deletor);
  
              m_resources[key] = std::weak_ptr&lt;model_t&gt;(tmp);
          }
          return tmp;
      }
  
  public:
      void Print() {
          std::cout &lt;&lt; "Content: ";
          for (const auto &amp;item : m_resources) {
              std::cout &lt;&lt; item.first &lt;&lt; " ";
          }
          std::cout &lt;&lt; std::endl;
      }
  
  private:
      static void releaseItem(std::weak_ptr&lt;self_t&gt; self, const key_t &amp;key, model_t *p) {
          std::shared_ptr&lt;Manager&lt;key_t, model_t&gt;&gt; mgr = self.lock();
          if (mgr) {
              mgr-&gt;m_resources.erase(key);
          }
          delete p;
      }
  
  private:
      std::map&lt;key_t, std::weak_ptr&lt;model_t&gt; &gt; m_resources;
  
      Manager() = default;
  };
  
  #endif //TENSOR_MANAGER_H
  
  </code></pre>
  
  <p>Now the compiler gives the errors:</p>
  
  <pre><code>/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2043:66: error: field of type 'Manager&lt;std::__1::basic_string&lt;char&gt;, int&gt;' has private default constructor
  _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
  </code></pre>