title: Abstract class and unique pointer
body: <p>I have the following error in my code: </p>
  
  <p><code>error: allocating an object of abstract class type 'Material'</code></p>
  
  <p>I don't know how to handle this case.</p>
  
  <p>I'm aware that <code>std::make_unique</code> performs an allocation, so it can't allocate the object of type <code>Material</code>, but I don't know how to correct it.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  struct Material
  {
    Material() = default;
    virtual int get_color() const = 0;
  };
  
  struct Basic : public Material
  {
    Basic() = default;
    virtual int get_color() const override
    {
      return 1;
    }
  };
  
  struct Mix : public Material
  {
    Mix(const Material&amp; mat1, const Material&amp; mat2)
      : mat1_(std::make_unique&lt;Material&gt;(mat1))
      , mat2_(std::make_unique&lt;Material&gt;(mat2))
    {}
  
    virtual int get_color() const override
    {
      return mat1_-&gt;get_color() + mat2_-&gt;get_color();
    }     
  private:
    std::unique_ptr&lt;Material&gt; mat1_;
    std::unique_ptr&lt;Material&gt; mat2_;
  };
  
  int main()
  {
    auto mix = Mix(Basic(), Basic());
    std::cout &lt;&lt; mix.get_color() &lt;&lt; '\n';
  }
  </code></pre>