C++ 智能感知 : expression must be a modifiable lvalue

标签 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);
 }
}

最佳答案

您的成员函数是 const 限定的。不能从 const 限定的成员函数中修改任何成员变量,除非它们被声明为可变的。

您需要使 pDrawMesh 可变,从 DrawMeshContainer 中删除 const 限定,或者找到一些其他方法来完成您想要完成的任何事情。

关于C++ 智能感知 : expression must be a modifiable lvalue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4180437/

相关文章:

c++ - 试图理解类和标题

c++ - C++中的常量映射初始化

c++ - 在 Azure Pipelines 中安装 Windows SDK 8.1 版本

c++ - 错误 C2664 : 'MessageBoxA' : cannot convert parameter 2 from 'std::string' to 'LPCSTR'

c++ - 如何直接使用 OleDB 创建并执行 SQL 命令?

c++ - 三个原子变量上的 CompareAndExchange

c++ - WASAPI + windows store 应用程序初始化

c - 我的自定义 ListView 控件中发生了什么导致滚动时部分或完全不重新绘制行?

c - 规范化 _int64 的随机值

c++ - 将磁贴添加到 MFC 应用程序