c++ IntelliSense:表达式必须是可修改的左值
我收到这两个错误,
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);
}
}
im getting these two errors
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
i declared pDrawMesh in my class than used it in one function.
here is my class
class CXFileEntity
{
......
LPD3DXMESH pDrawMesh;
.....
};
here is where i used the variable
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的成员函数是 const 限定的。您不能在 const 限定成员函数中修改任何成员变量,除非它们被声明为可变的。
您需要使
pDrawMesh
可变,从DrawMeshContainer
中删除 const 限定,或者找到其他方法来完成您想要完成的任务。Your member function is const-qualified. You cannot modify any member variables from within a const-qualified member function unless they are declared mutable.
You need to make
pDrawMesh
mutable, remove the const-qualification fromDrawMeshContainer
, or find some other way to accomplish whatever it is you are trying to accomplish.pDrawMesh
实际上是this->pDrawMesh
。但由于当前方法是一个const
方法,因此this
是一个const CXFileEntity*
。所以你不能设置成员pDrawMesh
。如果
DrawMeshContainer
确实应该更改CXFileEntity
,请从方法类型中删除该const
。如果DrawMeshContainer
“有效地”保持CXFileEntity
常量,并且pDrawMesh
成员“并不真正计入”您的const< 的含义/code> 对于对象,您可以将成员更改为
可变
。pDrawMesh
is reallythis->pDrawMesh
. But since the current method is aconst
method,this
is aconst CXFileEntity*
. So you can't set the memberpDrawMesh
.If
DrawMeshContainer
really should change theCXFileEntity
, remove thatconst
from the method type. IfDrawMeshContainer
"effectively" keeps theCXFileEntity
constant and thepDrawMesh
member "doesn't really count" toward your meaning ofconst
for the object, you can change the member to bemutable
.