为什么我收到“未在此范围内声明”的信息错误?
我在以下代码片段中收到 5 个错误,
其中 4 个错误是
“(”之前应有非限定 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
}
I get 5 errors at the following snippet of code
4 of the errors are
expected unqualified-id before '('
token|
and 1 error
'GetEntityIterator' was not declared
in this scope|
GetEntityIterator()
returns vector<*Entity>::iterator EntityIterator
GetAABB()
returns an AABB
I can post more code if needed
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是因为这个语法:
?
我不确定您想要做什么,但
->
运算符后面应该跟有该类成员的名称。编辑
阅读 iaamilind 的评论后,我终于想我明白你想要做什么。您试图取消引用迭代器,但仍然必须取消引用它返回的指针 (
Entity*
),因此->
运算符还不够。您必须使用括号和*
运算符是正确的 - 但您将它们放在了错误的位置。这是你应该做的:Maybe because of this syntax:
?
I'm not sure what you were trying to do, but the
->
operator is supposed to be followed by the name of a member of the class.Edit
After reading iaamilind's comment, I finally think I understand what you were trying to do. You were trying to dereference the iterator, but then you still had to dereference the pointer (
Entity*
) it returned, so the->
operator was not enough. You're correct that you have to use parentheses and the*
operator - but you've put them in the wrong place. This is what you should do:从您的代码看来,
GetEntityIterator()
返回指针。尝试将其更改为,GetEntityIterator()
(即删除其前面的指针*
)。例如,还要确保在类中声明/定义了此类函数。
From your code it looks that
GetEntityIterator()
returns pointer. Try changing it to,GetEntityIterator()
(i.e. remove the pointer*
ahead of it). e.g.Also make sure that such function is declared/defined in the class.