title: DirectX/C++ How to Dereference Vector Data Array to Initialize D3D11 SUBRESOURCE DATA
body: <p>I am trying to pass a pointer to an array of Vertex Data, (base class member) into a method used to initialize the Direct3D Vertex Buffer, (ID3D11Buffer).</p>
  
  <p>I want to use the variable, "v4", the pointer to the array, but I think I am not dereferencing the pointer correctly.  Could someone point me in the right direction?</p>
  
  <p>I have tried many ways to make this assignment, but I can only get a basic array work, (sometimes I end up with casting to "const void *" errors).</p>
  
  <p>How would I use a pointer?  </p>
  
  <p>The line I am having issue with is ...
  vertexSubResourceData.pSysMem = v1;</p>
  
  <p>(p.s. Using the V.S. C++ Nov 2012 CTP compiler .. not released yet ..)</p>
  
  <p>*<strong>Answered:  Have confirmed that it is a Visual Studio 2012 C++ Nov. CTP Compiler Bug.  Arrays of Vector structures declared, even outside of the class, using C++ 11 initialization syntax are being interpreted incorrectly, (unless of course I am using the incorrect array initialization syntax).  Also Note:  This only pertains to initialization lists associated with pointers. *</strong></p>
  
  <p>Thanks!</p>
  
  <p>// Simplified Code</p>
  
  <pre><code>void Triangle::InitializeVertexBuffer()
  {
      struct V
      {
          float X, Y, Z;    // vertex position
      };
  
      // Compiles But doesn't work as desired.
      // changed from V* v4 = new V[] // Compiled without range.
      // Pointer to this data would ideally come from base static pointer, or file.
      V* v4 = new V[3]     
      {
          { 0.50f, 0.5f, 0.0f },
          { 0.50f, -0.5f, 0.0f },
          { -0.50f, -0.5f, 0.0f },
      };
  
      // Compiles and Works to prove compiler issue with initialization lists. 
      V* vectorList = new V[3];
      vectorList[0].X = 0.5f;
      vectorList[0].Y = 0.5f;
      vectorList[0].Z = 0.00f;
  
      vectorList[1].X = 0.5f;
      vectorList[1].Y = -0.5f;
      vectorList[1].Z = 0.00f;
  
      vectorList[2].X = -0.5f;
      vectorList[2].Y = -0.5f;
      vectorList[2].Z = 0.00f;
  
  
      unsigned int size = sizeof(V) * 3; //sizeof(* Model::Vertices);
  
      // The Description of the Vertex Buffer
      D3D11_BUFFER_DESC vertexBufferDescription = {0};
      vertexBufferDescription.ByteWidth = size;
      vertexBufferDescription.BindFlags = D3D11_BIND_VERTEX_BUFFER; 
  
      // Model Data to be transferred to GPU Buffer.
  
      D3D11_SUBRESOURCE_DATA vertexSubResourceData = {0};
      vertexSubResourceData.SysMemPitch = 0;
      vertexSubResourceData.SysMemSlicePitch = 0;
  
      // Can't figure out how to dereference v4
  
      vertexSubResourceData.pSysMem = vectorList; // works, but using "v4" doesn't.
  
      // vertexSubResourceData.pSysMem = Model::Vertices; 
      // This is what I /really/ want .. Pointer to vertice array data from base class
  
  
      NS::DeviceManager::Device-&gt;CreateBuffer(
          &amp;vertexBufferDescription, 
          &amp;vertexSubResourceData, 
          &amp;NS::ModelRenderer::VertexBuffer);
  }
  </code></pre>