gpt4 book ai didi

c++ - 类型未声明 C++

转载 作者:行者123 更新时间:2023-11-30 01:55:51 25 4
gpt4 key购买 nike

您好,我正在为我的 CS 类(class)制作游戏,但我遇到了一个我不明白的非常奇怪的错误。我创建了一个函数,它接受一个整数和对我创建的另一种类型的引用。

错误是:

In file included from PC.h:3:0,
from Grid.h:4,
from testmain.cc:1:
Character.h:23:20: error: ‘Grid’ has not been declared

字符.h

#ifndef __CHARACTER_H__
#define __CHARACTER_H__
#include "Entity.h"
#include "Grid.h"
using namespace std;
class Character : public Entity{

int hp;
int atk;
int def;
char prev;

public:
Character(int x, int y, char s, int hp, int atk, int def);
int getHp();
int getAtk();
int getDef();
void setHp(int i);
void setAtk(int i);
void setDef(int i);
void attack(Character &c);
bool move(int dir, Grid &g);

};
#endif

网格.h

#ifndef __GRID_H__
#define __GRID_H__
#include "Entity.h"
#include "PC.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

/*
Class Grid is only created once per game, it holds information about the level layout
and the population of the grid (ie.Entities).
*/

class Grid{


int sLoc[25][79]; //holds potential spawn locations
int rNum[5]; //holds the number of spawnable locations in each room

int level; //the current level, used for reading in the maps/current level
int playerRoom; //holds the room that the player will spawn in, necessary for stair-spawn restrictions
int dragons; //hold number of spawned dragons
void readLevel(); //reads in the current level from a text file in the same dir. with the correct name ("1.txt", "2.txt"...)
void addHero(PC &hero); //takes in an hero and adds it to the array of Entities
void addStairs(); //adds the stairs in a different room than the player
void addGold(); //distributes gold across the board
void addPots(); //distributes potions across the board
void addtheD(int x, int y);//adds dragons
void addMonsters(); //adds monsters
void checkRNum(); //fills in rNum with the corresponding amount of tiles per room
void readLoc(); //identifies where all rooms begin and end
void printLoc(); //prints the sloc arrays, for testing p urposes
void clear(); //cleares all entities left on the board and takes care of memory deletion
void populate(PC &hero); //populates the board with rng monsters

public:
Grid(); //default constructor, no parameters necessary as every game starts at level one with no population or map
void gg(PC &hero); //increases level by 1 (goes to next level)
void printBoard(); //prints out the map layout and the symbols that indicate which Entites are present
char boardAt(int x, int y);
char Board[25][79]; //the maps layout as well as information about which Entity occupies a given position (if any)
Entity* population[25][79];//holds pointers to the Entities that populate the board
};
#endif

您认为这是什么原因造成的?我包含了网格头文件,我认为这应该没问题?

最佳答案

PC.hGrid.h 之间存在循环依赖。

Grid 需要 PC,PC 需要 Grid。至少有一种方法,GridPC 尚不可用。

使用前向声明或重构。

关于c++ - 类型未声明 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20318935/

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