我不知道如何描述它,但是我声明了一个类(movableBox),但无法在特定范围内使用(该范围在类播放器中)。
这是我的一些代码:
玩家等级:
#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
和movingBox类:
#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
我收到此错误:
CodeBlocksProjects/phys/player.h:18:110: error: ‘movableBox’ was not declared in this scope
如您所见,我缺乏解释,我不知道为什么或如何发生,我希望您理解我的问题。
提前致谢! :)
最佳答案
这是一个循环依赖性问题。在#include "movablebox.h"
中有player.h
,在#include "player.h"
中也有movablebox.h
。
您已经在player
中转发了movablebox.h
类,这似乎足够了;因此只需从#include "player.h"
中删除movablebox.h
。
关于c++ - 类未在作用域中声明,但已声明该类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46620778/