Compiler insists a class member doesn't exist

Hello all,

I'm getting the following compiler error:
EntityManager.cpp|54|error: 'class Entity' has no member named 'deleteFlag'

However, the Entity class very decidedly does have a member named "deleteFlag."
Here is the offending code from EntityManager.cpp's UpdateAll() function:
1
2
3
4
5
6
7
8
9
10
void EntityManager::UpdateAll(float gravAcceleration, sf::Vector2f center)
{
    std::map<std::string, Entity *>::const_iterator itr = _entityMap.begin();
    while (itr != _entityMap.end())
    {
        if(itr->second->deleteFlag == true){Remove(itr->first);}
        else {itr->second->Update(gravAcceleration, center);}
        itr++;
    }
}


deleteFlag is simply a bool declared public in Entity. There's nothing special about it, and I have no idea why my compiler insists it doesn't exist. Renaming it doesn't work, making it a private variable with getters and setters doesn't work, making it not static doesn't work (and I'd like it to be static)... I'm out of ideas. Just for the sake of being thorough, here is a very abbreviated class declaration from Entity.h:

1
2
3
4
5
6
class Entity
{
public:
    Entity(bool hasGravityForce);
    static bool deleteFlag;
}


And Entity's constructor:
1
2
3
4
5
Entity::Entity(bool hasGravityForce)
{
    _hasGravityForce = hasGravityForce;
    deleteFlag = false;
}


Thanks for your help, as always!
There is nothing wrong with the code you have posted. You must be mistaking or compiling the wrong files or something.
Well that's good to hear, I suppose. I did recently rename the class Entity (from Entities), could that have anything to do with it?

EDIT: Yup, I was still including "Entities.h" in my Entity Manager instead of "Entity.h"

Thanks for putting me on the right track!
Last edited on
For your description it seems that EntityManager.cpp is not including the updated Entity.h

I'd like it to be static
¿are you sure? ¿wouldn't your function just be `kill_them_all' or `update_them_all' then?

Also, if Remove() erase an element from the map, then your iterator will be invalidated.
Right, that was exactly the problem.

Re:static, I think you're probably right, I will change that.

And you're right again! I need to make sure not to screw up the iterator.

Thank you so much!
Topic archived. No new replies allowed.