C++表达式必须是可修改的值
C++ expression must be a modifiable value
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 = { ... };
只能在定义变量时使用。在代码中,平面顶点用于赋值表达式。那里不允许使用初始化语法。这是一个语法错误。
稍后,您将定义一个局部变量 PlaneIndices,该变量将在退出方法后被丢弃。
你不能像这样为PlaneVertices
数组赋值,只有在使用 {} 表示法定义它来初始化它时才能使用它。尝试使用 for 循环将每个元素分配给数组的每个独立元素
编辑:为了响应您的评论,创建 PLANE 结构的实例并为其分配您希望它具有的值。然后PlaneVertices
使用
PlaneVertices[0] = // instance of PLANE struct you have just created
然后对数组中所需的其余 3 个 PLANE 实例重复此操作,将 1、2 和 3 个索引添加到 PlaneVertices
的 1、2 和 3 个索引中。为了充分说明,我将使用您提供的数据为您做第一个
PLANE plane_object;
plane_object.X = 1.0*size;
plane_object.Y = 0.0;
plane_object.Z = 1.0*size;
plane_object.Normal = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
plane_object.U = 0.0;
plane_object.V = 0.0;
PlaneVertices[0] = plane_object;
然后,您需要对要添加的每个平面重复此操作。也不要拿关于你的平面指数问题的其他答案。
相关文章:
- 对于结构,表达式必须是可修改的ivalue
- 表达式必须是可修改的左值.科迪米
- 错误:表达式必须是可修改的 I值
- 如何修改Lambda表达式以将输出放入文本文件
- 表达式必须是可修改的左值 Errror
- 错误表达式必须是插入函数(二叉树 C++)中的可修改 Ivalue
- 表达式必须是带有枚举的可修改左值
- 表达式必须是可修改的右值C++
- 循环赋值的多维数组:表达式必须是可修改的左值
- 修改正则表达式以包含反斜杠和单引号(以便反斜杠表现为转义字符)
- C++ 时间存储time_point表达式必须是可修改的左值
- 在 lambda 表达式中自动推导出的类型是什么,用于修改 bool 类型的向量(特殊容器)
- 表达式必须是可修改的lvalue:`(x,y)= 0;`
- 将值分配给指针时:表达式必须是可修改的lvalue
- 错误:表达式必须是可修改的LVALUE
- 通过使用模板类,表达式必须是可修改的LVALUE
- 表达式必须是可修改的左值
- 表达式必须是可修改的左值(字符数组)
- boost.proto+就地修改表达式树
- 当 f & g 修改相同的全局变量时,表达式 f() 的值是否> g() 未定义或未指定?