title: C++ unique_ptr separate declaration and instantiation
body: <p>Maybe this is a very simple question. But as a Java programmer I'm still struggeling how to instantiate objects correctly in C++. I got a member variable in my class and I can't instantiate it in the instantiation list of the class constructor (because it depends on some cofiguration values): </p>
  
  <pre><code>class SomeClass{    
    private:
    ObjectType mObject; //declaration and instantiation??
  
    public: 
    SomeClass()/*:mObject(valueA,valueB)*/{ 
       //read config here...
       //now we got valueA and valueB
       mObject = mObject(valueA,valueB);
    }    
  };
  </code></pre>
  
  <p>The code as shown above does not work, because the C++ tries to call <code>mObject()</code> before <code>mObject(valueA, valueB)</code> is even reached.
  I got two question:</p>
  
  <ol>
  <li>Do I need to use a pointer in this case?</li>
  <li>How can I use a <code>unique_ptr</code> for this? I already searched for examples but didn't find one with separate declaration and instantiation. (like <a href="https://msdn.microsoft.com/de-de/library/hh279676.aspx" rel="nofollow">here</a>)</li>
  </ol>
  
  <p>I get an error if I try to use <code>unique_ptr</code> like this:</p>
  
  <pre><code> #include &lt;memory&gt;
    class SomeClass{    
        private:
        std::unique_ptr&lt;ObjectType&gt; mObject;
  
        public: 
        SomeClass(){ 
           //read config here...
           //now we got valueA and valueB
           mObject = new ObjectType(valueA,valueB);
        }    
      };
  </code></pre>
  
  <p>the Error is:</p>
  
  <blockquote>
    <p>Error: no match for 'operator=' (operand types are
    'std::unique_ptr' and 'ObjectType*')
         mObject= new ObjectType(valueA, valueB)</p>
  </blockquote>
  
  <p>Maybe there is even a better solution which I didn't see yet.</p>