1

これらの2つのエラーが発生します

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

1つの関数で使用するよりも、クラスで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);
 }
}
4

2 に答える 2

4

メンバー関数はconst-qualifiedです。可変であると宣言されていない限り、const修飾メンバー関数内からメンバー変数を変更することはできません。

変更可能にするかpDrawMesh、const-qualificationをから削除するDrawMeshContainerか、または達成しようとしていることを達成するための他の方法を見つける必要があります。

于 2010-11-14T23:56:10.717 に答える
0

pDrawMesh本当にthis->pDrawMeshです。ただし、現在のメソッドはconstメソッドであるため、thisconst CXFileEntity*です。したがって、メンバーを設定することはできませんpDrawMesh

DrawMeshContainer本当に変更する必要がある場合は、メソッドタイプからCXFileEntityそれを削除します。「効果的に」定数を維持し、メンバーがオブジェクトの意味に「実際にはカウントされない」const場合は、メンバーをに変更できます。DrawMeshContainerCXFileEntitypDrawMeshconstmutable

于 2010-11-14T23:57:31.537 に答える