title: Pushing back a pointer into a vector c++
body: <p>This is a follow up to <a href="https://stackoverflow.com/questions/16022035/using-vectors-to-store-different-objects-inherited-from-the-same-parent-class-c">Using vectors to store different objects inherited from the same parent class c++</a> but you don't need to read it to understand.</p>
  
  <p>I have a polynomial class and another class that is a container class. In the container class there is a vector that holds pointers to polynomials.
  I have defined vectorPolynomial this way:</p>
  
  <pre><code>std::vector&lt;std::unique_ptr&lt;Polynomial&gt;&gt; vectorPolynomial;
  </code></pre>
  
  <p>In the polynomial class there is a binary operator that do an operation that takes two polynomials and returns the result which is a polynomial itself.</p>
  
  <p>Before polymorphism the operator returned an object of type Polynomial and I just did this:</p>
  
  <pre><code>Polynomial polynomialresult = polynomial1 % polynomial2;
  vectorPolynomial.push_back(polynomialresult);
  </code></pre>
  
  <p>Now since the vector is not a vector of polynomials anymore, this won't work. Here is what I tried:</p>
  
  <pre><code>std::unique_ptr&lt;Polynomial&gt; result(new Polynomial);
  *result = *(vectorPolynomial[i]) % *(vectorPolynomial[j]);
  vectorPolynomial.emplace_back(result);
  </code></pre>
  
  <p>This didn't work. I also tried:</p>
  
  <pre><code>Polynomial * result = new Polynomial;
  </code></pre>
  
  <p>instead of the unique_ptr but it didn't work either. push_back instead of emplace_back does not work either.</p>
  
  <p>How is this typically done?</p>