[英]Accessing pointers inside objects
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.
在我的主要DX11项目中,我正在制作D3D11_SUBRESOURCE_DATA以创建顶点缓冲区。 When I create a subresource I need to reference the vector like so:
创建子资源时,我需要像这样引用向量:
subresourcedata.pSysMem = &vertices; 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 . 但是现在顶点在对象中了,我不确定该怎么做(cube.vertices不一样),该对象是否必须是指针,所以我可以使用->代替。 to reference them or is there a simple way to do what I'm doing using normal objects?
引用它们还是有一种简单的方法来使用普通对象做我正在做的事情?
Thanks 谢谢
Just add an accessor to your class to expose the vertices as a pointer. 只需在类中添加访问器,即可将顶点显示为指针。 So, assuming you have a
Vertex
structure, something like: 因此,假设您具有
Vertex
结构,则类似于:
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();
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; 立方体c;
subresourcedata.pSysMem = &c; subresourcedata.pSysMem =&c;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.