【发布时间】:2013-01-26 20:20:01
【问题描述】:
我尝试在我的代码中引用另一个类的结构,它给了我一个错误,说我有语法问题。
#pragma once
#include "Definitions.h"
#include "GV.h"
#include "UI.h"
#include "Tile.h"
#include "Item.h"
class Figure {
public:
//Figure index
struct FIGURE_TYPE {
//Where to crop the image from
SDL_Rect crop;
int x;
int y;
};
//The game figure
FIGURE_TYPE figure_index[FIGURE_COUNT];
//The figure array
int figure_array[MAP_HEIGHT / 64][MAP_WIDTH / 64];
//Functions
Figure ( void );
bool draw_figures ( SDL_Surface* screen, SDL_Surface* figures, SDL_Rect camera, Figure::FIGURE_TYPE figure_spec[FIGURE_COUNT] );
};
这就是Figure.h中的结构,
#pragma once
#include "Definitions.h"
#include "GV.h"
#include "Tile.h"
#include "Item.h"
#include "Figure.h"
class UI {
public:
UI ( void );
void set_camera ( SDL_Rect& camera, Figure::FIGURE_TYPE figure_spec[FIGURE_COUNT] );
bool draw_map ( SDL_Surface* screen, SDL_Rect& camera, SDL_Surface* tiles, SDL_Surface* figures, Figure::FIGURE_TYPE figure_spec[FIGURE_COUNT] );
bool draw_status ( void );
};
这就是我从另一个名为 UI.h 的头文件中引用它的地方。我知道引用结构存在问题,我只是不知道如何解决它。很简单的问题,有人要帮忙吗?
问题不是 Figure Type 是在 Figure.h 之外声明的,或者它是私有的而不是公共的。
错误报告
Error 1 error C2653: 'Figure' : is not a class or namespace name c:\users\jim\documents\c++\roguelike\roguelike\ui.h 13 1 roguelike
错误 3 错误 C2653: 'Figure' : 不是类或命名空间名称 c:\users\jim\documents\c++\roguelike\roguelike\ui.h 14 1 roguelike
错误 2 错误 C2061:语法错误:标识符 'FIGURE_TYPE' c:\users\jim\documents\c++\roguelike\roguelike\ui.h 13 1 roguelike
错误 4 错误 C2061:语法错误:标识符 'FIGURE_TYPE' c:\users\jim\documents\c++\roguelike\roguelike\ui.h 14 1 roguelike
【问题讨论】:
-
你认为
Figure::在做什么?你认为Figure是命名空间吗?一种?或者是其他东西? (当我不知道你的推理是什么时,很难纠正你的误解。) -
对不起,Figure.h 包含一个名为 Figure 的类声明。我认为 Figure:: 是一种引用它的方式。
-
请包含整个错误消息。该消息是对问题所在和位置的解释。
-
我已经添加了您应该需要的所有代码和错误报告。
-
@DavidSchwartz:
Figure是一个类类型。你错了。 OP 的语法和理解是 100% 正确的。
标签: c++