0

I have an object called cube and I have a vector of vertices within it. Within my main DX11 project I'm making D3D11_SUBRESOURCE_DATA in order to create a vertex buffer. When I create a subresource I need to reference the vector like so:

subresourcedata.pSysMem = &vertices;

But now that the vertices are in an object I'm not sure how to do that (cube.vertices isn't the same), does the object have to be a pointer so I can use -> instead of . to reference them or is there a simple way to do what I'm doing using normal objects?

Thanks

1
  • 2
    You should post a small fragment of code that illustrates your problem succinctly. Commented Dec 5, 2013 at 16:12

2 Answers 2

3

Just add an accessor to your class to expose the vertices as a pointer. So, assuming you have a Vertex structure, something like:

class CMyCube
{
    // ... blah blah

public:
    const Vertex* GetVertices() const { return &m_pVertices[0]; }

    // ... blah blah

private:
    std::vector<Vertex> m_pVertices;
};

Then you can do:

pSubResource.pSysMem = pSomeCubeInstance.GetVertices();
Sign up to request clarification or add additional context in comments.

Comments

0

You could overload the & operator.

class cube
{
public:
    vertices* operator&() const { return &_vertices[0]; }

    std::vector<vertices> _vertices;
};

Then you can do this:

cube c;

subresourcedata.pSysMem = &c;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.