gpt4 book ai didi

c++ - 类未在范围内声明但类已声明

转载 作者:行者123 更新时间:2023-11-28 01:42:27 25 4
gpt4 key购买 nike

我不知道如何描述这一点,但我声明了一个类 (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

和 movableBox 类:

#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

由于我缺乏解释,您可以看出我不知道为什么会发生这种情况,也不知道它是如何发生的,希望您能理解我的问题。提前致谢! :)

最佳答案

这是一个循环依赖问题。 player.h中有#include "movablebox.h"movablebox.h中有#include "player.h"

您在 movablebox.h 中有转发类 player 并且这似乎足够了;所以只需从 movablebox.h 中删除 #include "player.h"

关于c++ - 类未在范围内声明但类已声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46620778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com