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

发布于 2024-11-10 00:39:17 字数 2347 浏览 0 评论 0原文

我在以下代码片段中收到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煮茶煮酒煮时光 2024-11-17 00:39:17

也许是因为这个语法:

getEntityManager()->(*GetEntityIterator())

我不确定您想要做什么,但 -> 运算符后面应该跟有该类成员的名称。

编辑

阅读 iaamilind 的评论后,我终于想我明白你想要做什么。您试图取消引用迭代器,但仍然必须取消引用它返回的指针 (Entity*),因此 -> 运算符还不够。您必须使用括号和 * 运算符是正确的 - 但您将它们放在了错误的位置。这是你应该做的:

(*EGame_Manager->getEntityManager()->GetEntityIterator())->GetType()

Maybe because of this syntax:

getEntityManager()->(*GetEntityIterator())

?

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:

(*EGame_Manager->getEntityManager()->GetEntityIterator())->GetType()
窝囊感情。 2024-11-17 00:39:17

从您的代码看来,GetEntityIterator() 返回指针。尝试将其更改为,
GetEntityIterator()(即删除其前面的指针*)。例如

EGame_Manager->getEntityManager()->GetEntityIterator()->GetType();

,还要确保在类中声明/定义了此类函数。

From your code it looks that GetEntityIterator() returns pointer. Try changing it to,
GetEntityIterator() (i.e. remove the pointer * ahead of it). e.g.

EGame_Manager->getEntityManager()->GetEntityIterator()->GetType();

Also make sure that such function is declared/defined in the class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文