struct PLANE {FLOAT X, Y, Z; D3DXVECTOR3 Normal; FLOAT U, V;};
class PlaneStruct
{
public:PLANE PlaneVertices[4];
public:DWORD PlaneIndices;
void CreatePlane(float size)
{
// create vertices to represent the corners of the cube
PlaneVertices =
{
{1.0f * size, 0.0f, 1.0f * size, D3DXVECTOR3(0.0f, 0.0f, 1.0f), 0.0f, 0.0f}, // side 1
{-1.0f * size, -0.0f, 1.0f * size, D3DXVECTOR3(0.0f, 0.0f, 1.0f), 0.0f, 1.0f},
{-1.0f * size, -0.0f, -1.0f * size, D3DXVECTOR3(0.0f, 0.0f, 1.0f), 1.0f, 0.0f},
{1.0f * size, -0.0f, -1.0f * size, D3DXVECTOR3(0.0f, 0.0f, 1.0f), 1.0f, 1.0f},
};
// create the index buffer out of DWORDs
DWORD PlaneIndices[] =
{
0, 2, 1, // side 1
0, 3, 2
};
}
};
这是我的“平面”结构代码,我只有一个问题,如果您看一下顶部,上面写着 PLANE PlaneVertices[4];然后在一个函数中我想定义它,以便给它特定的值,但是我得到以下错误: 表达式必须是可修改的值。 请帮忙
最佳答案
在 C++ (2003) 初始化中,像 StructX var = { ... };
只能在定义变量时使用。在您的代码中,PlaneVertices 用于赋值表达式。那里不允许初始化语法。这是语法错误。
稍后您定义一个局部变量 PlaneIndices,该变量将在方法退出后被丢弃。
关于C++ 表达式必须是可修改的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11273076/