The problem is this. I have a Level class, where there is a method of colliding with a map, it is common both for the player and for the enemies. And the class of enemies, where this method is called, because the enemy must run at the level (like the player).

As a result, I ran into the problem of declaring classes when using the class method BEFORE the description of the class itself. You could just swap the Entity and Level classes. But I want to keep a list of enemies in the Level class (if only because they are stored with the Tiled Map Editor level).

class Entity { public: bool solid = true, visible = true; void update(Level& level) { level.col(*this); } Entity() {} }; class Level {public: Level() { std::list <std::shared_ptr<Entity>> enemy; enemy.emplace_back(new Entity()); } void col(Entity& player) { } }; int main() { Level level; } 

When compiling swears on an undeclared identifier.

    1 answer 1

     class Level; // предварительное объявление class Entity { public: bool solid = true, visible = true; void update(Level& level); // идентификатор Level объявлен Entity() {} }; class Level { public: Level() { std::list <std::shared_ptr<Entity>> enemy; enemy.emplace_back(new Entity()); } void col(Entity& player) { } }; void Entity::update(Level& level) { level.col(*this); // идентификатор Level::col объявлен } 
    • I tried so hard, got Error C2027 using undefined type "Level" - LexPartizan am
    • @LexPartizan And which line in this code causes such an error? Do not forget to bring mcve - VTT
    • Thank you, I did not notice that you carried the method out of the class, now everything works! - LexPartizan