title: How to create a new value and assign to a private unique_ptr in a class constructor?
body: <p>How do I create new and assign a value to a private unique_ptr in the constructor of a class? Tyvm :^) Keith</p>
  
  <p>My best effort:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  class A {
  public:
      A() {};
      A(int);
      void print();
  private:
      std::unique_ptr&lt;int&gt; int_ptr_;
  };
  A::A(int a) {
      int_ptr_ = new int(a);
  }
  void A::print() {
      std::cout &lt;&lt; *int_ptr_ &lt;&lt; std::endl;
  }
  int main() {
      A a(10);
      a.print();
      std::cout &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Compiler result:</p>
  
  <pre><code>smartPointer2.1.cpp:13:11: error: no match for ‘operator=’ (operand types are ‘std::unique_ptr&lt;int&gt;’ and ‘int*’)
    int_ptr_ = new int(a);
  </code></pre>