nelsoncookie 23
nelsoncookie 23

Reputation: 47

class not declared in scope but the class is declared

I don't know how to describe this but I declare a class (movableBox) but am not able to use in a specific scope (this scope is in the class player).

Here is some of my code:

player class:

#ifndef PLAYER_H
#define PLAYER_H

#include <SFML/Graphics.hpp>
#include <vector>
#include "movablebox.h"

class player
{
    public:
        sf::RectangleShape* player;
        sf::Texture* playerTexture;
        sf::Vector2f speed;
        bool touching;

        static void create(sf::Vector2f pos_);
        static void draw(sf::RenderWindow& window);
        static void updatePos(float& dt, float gravity, std::vector<sf::RectangleShape*> solids, std::vector<movableBox::movableBox_*> movableBoxes);
        static void checkControls();
        static void checkControlsperEvent (sf::Event& event);
};

#endif // PLAYER_H

and the movableBox class:

#ifndef MOVABLEBOX_H
#define MOVABLEBOX_H

#include <SFML/Graphics.hpp>
#include <vector>
#include "player.h"

class player;

class movableBox
{
    public:

        struct movableBox_ {
            sf::RectangleShape* box;
            sf::Texture* texture;
            sf::Vector2f speed;
            bool selected;
            player* selectedBy;
            bool touching;
        };

        static void create(sf::Vector2f pos_, sf::Vector2f size_);
        static void draw(sf::RenderWindow& window);
        static void updatePos(float& dt, float gravity, std::vector<sf::RectangleShape*> solids);
        static void grabNearest(player* player);
};

#endif // MOVABLEBOX_H

I'm getting this error:

CodeBlocksProjects/phys/player.h:18:110: error: ‘movableBox’ was not declared in this scope

As you can tell by my lack of explaination I don't know why or how this happens, I hope you understand my problem. Thanks in advance! :)

Upvotes: 0

Views: 78

Answers (1)

songyuanyao
songyuanyao

Reputation: 172884

This is a circular dependency issue. There's #include "movablebox.h" in player.h, and also #include "player.h" in movablebox.h.

You have forward delcared class player in movablebox.h and it seems to be enough; so just remove #include "player.h" from movablebox.h.

Upvotes: 2

Related Questions