“敌人”没有在这个范围内宣布? [英] 'Enemy' was not declared in this scope?

查看:120
本文介绍了“敌人”没有在这个范围内宣布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我的错误:'敌人'没有在这个范围声明。错误是在map.h文件,即使map.h包括enemy.h如图所示

Okay, so thats my error: 'Enemy' was not declared in this scope.The error is in the map.h file, even though map.h includes enemy.h as shown

#ifndef MAP_H_INCLUDED
#define MAP_H_INCLUDED

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

#include "enemy.h"

#define MAX_TILE_TYPES 20

using namespace std;

class Map{
        public:
        Map();
        void loadFile(string filename);
        int** tile;
        int** ftile;
        bool solid[MAX_TILE_TYPES];
        int width;
        int height;
        int tileSize;

        vector<Enemy> enemies;

};

#endif // MAP_H_INCLUDED

这里是enemy.h



And here is enemy.h

#ifndef ENEMY_H_INCLUDED
#define ENEMY_H_INCLUDED

#include "global.h"
#include "map.h"

class Enemy{
        public:
        Enemy();
        Enemy(float nx, float ny, float nstate);
        void update(Map lv);
        bool rectangleIntersects(float rect1x, float rect1y, float rect1w, float rect1h, float rect2x, float rect2y, float rect2w, float rect2h);
        void update();
        float x;
        float y;
        Vector2f velo;
        float speed;
                float maxFallSpeed;
        int state;
        int frame;
        int width;
        int height;

        int maxStates;
        int *maxFrames;

        int frameDelay;

        bool facingLeft;
        bool onGround;

        bool dead;
        int drawType;
};

#endif // ENEMY_H_INCLUDED

任何人都知道发生了什么,修理它?

Anyone know whats going on and how to fix it?

推荐答案

您需要删除 #include 语句之一循环引用。为了允许代码编译你可以声明一个包含的类只是一个简单的定义

You need to remove one of the #include statements to break the circular reference. To allow the code to compile you can declare one of the included classes as just a simple definition

class Map;

,然后将标题包含在cpp文件。

in the top of the Enemy.hpp file, for example, and then include the header in the cpp file.

这篇关于“敌人”没有在这个范围内宣布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆