title: unique_ptr & vector, trying to access deleted function, Visual Studio 2013
body: <p>I am trying to use unique_ptr to manage my memory, and VS2013 seems to be giving me trouble when I think it shouldn't be.</p>
  
  <p>It would seem that the compiler is for whatever reason trying to access a deleted copy constructor when it really should have no reason to do so.</p>
  
  <p>This is what one of my classes looks like:</p>
  
  <pre><code>class Mesh
  {
  public:
      Mesh(oglplus::Program* program, const std::vector&lt;Vertex&gt;&amp; vertices, 
                      const std::vector&lt;GLuint&gt;&amp; indices);
      void draw();
  private:
      const oglplus::Program* _program;
      std::vector&lt;Vertex&gt; _vertices;
      std::vector&lt;GLuint&gt; _indices;
      oglplus::Buffer _faceBuffer;
      oglplus::Buffer _vertexBuffer;
      oglplus::VertexArray _vao;
  };
  
  class Model
  {
  public:
      Model(std::string filename, oglplus::Program* program);
      void draw();
  private:
      const oglplus::Program* _program;
      std::vector&lt;std::unique_ptr&lt;Mesh&gt;&gt; _meshes;
  };
  </code></pre>
  
  <p>The issue is with the line</p>
  
  <pre><code> std::vector&lt;std::unique_ptr&lt;Mesh&gt;&gt; _meshes;
  </code></pre>
  
  <p>it starts spewing things like</p>
  
  <pre><code>2&gt;c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(593): error C2280: 'std::unique_ptr&lt;Model::Mesh,std::default_delete&lt;_Ty&gt;&gt;::unique_ptr(const std::unique_ptr&lt;_Ty,std::default_delete&lt;_Ty&gt;&gt; &amp;)' : attempting to reference a deleted function
  2&gt;          with
  2&gt;          [
  2&gt;              _Ty=Model::Mesh
  2&gt;          ]
  2&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(1486) : see declaration of 'std::unique_ptr&lt;Model::Mesh,std::default_delete&lt;_Ty&gt;&gt;::unique_ptr'
  2&gt;          with
  2&gt;          [
  2&gt;              _Ty=Model::Mesh
  2&gt;          ]
  2&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(592) : while compiling class template member function 'void std::allocator&lt;_Ty&gt;::construct(_Ty *,const _Ty &amp;)'
  2&gt;          with
  2&gt;          [
  2&gt;              _Ty=std::unique_ptr&lt;Model::Mesh,std::default_delete&lt;Model::Mesh&gt;&gt;
  2&gt;          ]
  2&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(723) : see reference to function template instantiation 'void std::allocator&lt;_Ty&gt;::construct(_Ty *,const _Ty &amp;)' being compiled
  2&gt;          with
  2&gt;          [
  2&gt;              _Ty=std::unique_ptr&lt;Model::Mesh,std::default_delete&lt;Model::Mesh&gt;&gt;
  2&gt;          ]
  2&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\type_traits(572) : see reference to class template instantiation 'std::allocator&lt;_Ty&gt;' being compiled
  2&gt;          with
  2&gt;          [
  2&gt;              _Ty=std::unique_ptr&lt;Model::Mesh,std::default_delete&lt;Model::Mesh&gt;&gt;
  2&gt;          ]
  2&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector(650) : see reference to class template instantiation 'std::is_empty&lt;_Alloc&gt;' being compiled
  2&gt;          with
  2&gt;          [
  2&gt;              _Alloc=std::allocator&lt;std::unique_ptr&lt;Model::Mesh,std::default_delete&lt;Model::Mesh&gt;&gt;&gt;
  2&gt;          ]
  2&gt;          c:\users\vitali\projects\3d-stg\source\model\model.hpp(45) : see reference to class template instantiation 'std::vector&lt;std::unique_ptr&lt;Model::Mesh,std::default_delete&lt;_Ty&gt;&gt;,std::allocator&lt;std::unique_ptr&lt;_Ty,std::default_delete&lt;_Ty&gt;&gt;&gt;&gt;' being compiled
  2&gt;          with
  2&gt;          [
  2&gt;              _Ty=Model::Mesh
  2&gt;          ]
  2&gt;  model.cpp
  </code></pre>
  
  <p>I am not using <code>std::vector::resize()</code> or anything like that (in-fact I commented out all uses of my _meshes vector, and even tried commenting the implementation out completely to no avail), so I don't understand why the compiler is giving me issues.</p>
  
  <p>Does anybody have any ideas?</p>
  
  <hr>
  
  <p>Thank you Preetish Kakkar for finding the issue. It turns out it was an issue with compiler generated functions implicitly using the copy constructor and operator= of the Mesh class forcing the compiler to try and use deleted functions. </p>