繁体   English   中英

为什么我会收到“未在此范围内声明”错误?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM