1
$\begingroup$

Okay, so I'm currently using the IAGetVertexBuffers() method and I'd like to loop through some of the returned buffers to verify the contents.

However, I'm kind of new to DirectX and C++ in general. I tried using a a simple C++ 11 loop:

for (const auto& verts : veBuffer) {
        std::cout << verts << std::endl;

But I get an error saying this statement requires a suitable begin statement. Any suggestions would be appreciated at this point.

$\endgroup$
  • $\begingroup$ I am not a DirectX user, but I guess the problem here is probably that you used a pointer to some allocated memory (new/delete) as veBuffer. Have a look at into this question. So using a regular for loop (for (int i=0; i<SIZE, ++i)) should already fix your problem. $\endgroup$ – wychmaster Jun 24 at 18:47
  • $\begingroup$ Alternatively, you can use a std::vector as veBuffer, resize it to the necessary buffer size and pass the data pointer to your DirectX function with veBuffer.data(). $\endgroup$ – wychmaster Jun 24 at 18:52
2
$\begingroup$

There are a couple of issues. First you need to make sure that veBuffer has the correct type, so that probably means you need to cast it to pointer to vertex:

const auto vertices = reinterpret_cast<const Vertex*>(reBuffer);

Second a range-based for-loop needs to know where the range ends and giving it a raw pointer does not provide that information, so you cannot use it here. Instead you will need to know how many vertices there are and use a normal for-loop:

const size_t numVerts = 32;
for (size_t i = 0; i < numVerts; ++i) {
    const Vertex& vert = vertices[i];
    ...
}
| improve this answer | |
New contributor
trojanfoe is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.