[英]why am I getting a “was not declared in this scope” error?
我在以下代碼片段中遇到 5 個錯誤
其中4個錯誤是
'(' token| 之前的預期不合格 ID
和 1 個錯誤
'GetEntityIterator' 未在此范圍內聲明|
GetEntityIterator()
返回vector<*Entity>::iterator EntityIterator
GetAABB()
返回一個AABB
如果需要,我可以發布更多代碼
void Bomb::CreateExplosion(Game_Manager* EGame_Manager)
{
BombTexture->LoadTexture("Bomb.bmp");
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
for(int iteration = 1; iteration <= 3; iteration++)
{
if(this->GetAABB()->CheckForCollision(this->GetAABB(), EGame_Manager->getEntityManager()->(*GetEntityIterator())->GetAABB()) == true)//check for collision against the unbreakable blocks or player and does what is necessary for each
{
if(EGame_Manager->getEntityManager()->(*GetEntityIterator())->GetType() == unbreakableblock)
{
break;
}
else if(EGame_Manager->getEntityManager()->(*GetEntityIterator())->GetType() == player)
{
EGame_Manager->getEntityManager()->(*GetEntityIterator())->GetLives() -= 1;
}
}
else
glBegin(GL_QUADS);
glColor4f( 1.0f, 0.0f, 0.0f, 0.0f); //color red
glTexCoord2f(0.0, 0.0); //uv coordinates
glVertex3f( -2.0f + x,2.0f + y, 0.0f); //top left
//----------------------------------------------------
glColor4f( 0.0f, 1.0f, 0.0f, 0.0f); //color green
glTexCoord2f(1, 0.0 ); //uv coordinates
glVertex3f( 2.0f + x,2.0f + y, 0.0f); //top right
//----------------------------------------------------
glColor4f( 0.0f, 0.0f, 1.0f, 0.0f); //color blue
glTexCoord2f(1, 1);
glVertex3f( 2.0f + x, -2.0f + y, 0.0f); //bottom right
//----------------------------------------------------
glColor4f( 1.0f, 1.0f, 0.0f, 0.0f); //color red
glTexCoord2f(0.0, 1); //uv coordinates
glVertex3f(-2.0f + x, -2.0f + y, 0.0f); //bottom left
glEnd();
}
glDisable(GL_TEXTURE_2D); //disable 2d textures
}
也許是因為這種語法:
getEntityManager()->(*GetEntityIterator())
?
我不確定您要做什么,但->
運算符后面應該是 class 成員的名稱。
在閱讀了 iaamilind 的評論后,我終於想我明白你在做什么了。 您試圖取消引用迭代器,但您仍然必須取消引用它返回的指針 ( Entity*
),因此->
運算符還不夠。 你是正確的,你必須使用括號和*
運算符 - 但你把它們放在錯誤的地方。 這是你應該做的:
(*EGame_Manager->getEntityManager()->GetEntityIterator())->GetType()
從您的代碼看起來GetEntityIterator()
返回指針。 嘗試將其更改為GetEntityIterator()
(即刪除其前面的指針*
)。 例如
EGame_Manager->getEntityManager()->GetEntityIterator()->GetType();
還要確保在 class 中聲明/定義了這樣的 function。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.