c ++ IntelliSense:表达式必须是可修改的左值

时间:2010-11-14 23:50:05

标签: c++ winapi visual-c++ directx-9

我得到这两个错误

1>c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\xfileentity.cpp(376): error C3490: 'pDrawMesh' cannot be modified because it is being accessed through a const object
IntelliSense: expression must be a modifiable lvalue

我在班上宣布了pDrawMesh,而不是在一个函数中使用它 这是我的班级

class CXFileEntity
{
        ......
 LPD3DXMESH pDrawMesh;
        .....
};

这里是我使用变量

的地方
void CXFileEntity::DrawMeshContainer(LPD3DXMESHCONTAINER meshContainerBase, LPD3DXFRAME frameBase) const
{
 // Cast to our extended frame type
 D3DXFRAME_EXTENDED *frame = (D3DXFRAME_EXTENDED*)frameBase;  

 // Cast to our extended mesh container
 D3DXMESHCONTAINER_EXTENDED *meshContainer = (D3DXMESHCONTAINER_EXTENDED*)meshContainerBase;

 // Set the world transform But only if it is not a skinned mesh. 
 // The skinned mesh has the transform built in (the vertices are already transformed into world space) so we set identity
 // Added 24/08/10
 if (meshContainer->pSkinInfo)
 {
  D3DXMATRIX mat;
  D3DXMatrixIdentity(&mat);
  m_d3dDevice->SetTransform(D3DTS_WORLD, &mat);
 }
 else
  m_d3dDevice->SetTransform(D3DTS_WORLD, &frame->exCombinedTransformationMatrix);


 // Loop through all the materials in the mesh rendering each subset
 for (unsigned int iMaterial = 0; iMaterial < meshContainer->NumMaterials; iMaterial++)
 {
  // use the material in our extended data rather than the one in meshContainer->pMaterials[iMaterial].MatD3D
  m_d3dDevice->SetMaterial( &meshContainer->exMaterials[iMaterial] );
  m_d3dDevice->SetTexture( 0, meshContainer->exTextures[iMaterial] );

  // Select the mesh to draw, if there is skin then use the skinned mesh else the normal one
  pDrawMesh = (meshContainer->pSkinInfo) ? meshContainer->exSkinMesh: meshContainer->MeshData.pMesh;

  // Finally Call the mesh draw function
  pDrawMesh->DrawSubset(iMaterial);
 }
}

2 个答案:

答案 0 :(得分:4)

您的成员函数是const限定的。除非声明为可变,否则不能在const限定的成员函数中修改任何成员变量。

你需要使pDrawMesh变为可变,从DrawMeshContainer中移除const限定,或找到其他方法来完成你想要完成的任何事情。

答案 1 :(得分:0)

pDrawMesh真的是this->pDrawMesh。但由于当前方法是const方法,thisconst CXFileEntity*。因此,您无法设置成员pDrawMesh

如果DrawMeshContainer确实应该更改CXFileEntity,请从方法类型中删除const。如果DrawMeshContainer“有效”使CXFileEntity保持不变且pDrawMesh成员“并未真正计入”const对象的含义,则可以更改该成员成为mutable