English 中文(简体)
为什么我会得到一个“未在此范围内声明”的错误?
原标题:why am I getting a "was not declared in this scope" error?

我在下面的代码片段中得到了5个错误

其中4个错误是

expected unqualified-id before ( token|

和1个错误

GetEntityIterator was not declared in this scope|

GetEntityIterator()返回向量<*实体>;:迭代器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())

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

Edit

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

(*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();

还要确保在类中声明/定义了这样的函数。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签