这里有什么问题? - ISO C++禁止声明没有类型的'Circle'
也许你可以帮助我解决这个问题。 我有一个用来画圆一类,但是编译器发出此消息:这里有什么问题? - ISO C++禁止声明没有类型的'Circle'
In file included from ./Includes.h:19,
from ./Circle.h:8,
from ./Circle.cpp:5:
./GameApp.h:24: error: ISO C++ forbids declaration of 'Circle' with no type
./GameApp.h:24: error: expected ';' before '*' token
这里是GameApp.h:
#include "Includes.h"
class GameApp {
public:
GameApp();
~GameApp();
void Render();
protected:
void InitGU();
bool Controls();
void *dList; // display List, used by sceGUStart
void *fbp0; // frame buffer
Circle* circle;
};
的INCLUDE.H看起来是这样的:
//************************************************************************
// Includes.h
//************************************************************************
#include <malloc.h> //For memalign()
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdio.h>
#include <psprtc.h> // for the timer/fps functions
#include <pspctrl.h>
#include <math.h>
// GU
#include <pspgu.h>
#include <pspgum.h>
// Custom
#include "GameApp.h"
#include "Circle.h"
//************************************************************************
// Definitions
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define sin_d(x) (sin((x)*M_PI/180))
#define cos_d(x) (cos((x)*M_PI/180))
#define tan_d(x) (tan((x)*M_PI/180))
//************************************************************************
// structs, datatypes...
#ifndef VERTEX_TYPE_
#define VERTEX_TYPE_
typedef struct {
unsigned int color;
float x, y, z;
} vertex;
#endif
而且Circle.h
//************************************************************************
// Circle.h
//************************************************************************
#ifndef CIRCLE_H_
#define CIRCLE_H_
#include "Includes.h"
class Circle {
public:
Circle(float r1);
~Circle();
void Render();
float r;
float x, y;
float vx, vy;
protected:
vertex* vertices;
int n;
};
#endif
做不是使用一个庞大的包含到包含的一切(预编译头除外)。这几乎肯定会导致头痛。
包括你需要的东西,没有更多。它会解决你的问题。
您可以转发声明Circle
,作为DanDan suggested,但修复您的包含问题将从长远角度帮助您更多。
对于Include.h中的“defined”或顶点的类型定义,你会怎么说? – jex 2010-07-28 20:26:38
您可能有循环包含。使用前向声明:
class GameApp {
class Cicle;
...
你刚刚宣布的类Cicle [原文如此]作为GameApp中的嵌套类。编译器然后会去寻找一个类GameApp :: Cicle的实现。前向声明应该在GameApp的定义之外(以及之前)。 – 2010-07-28 21:05:37
我会检查你的make文件,以确保构建是正确的顺序,然后,包括在每一个.H顶尖既.H尝试,如果结合班上有两个简单。祝你好运
Includes.h在包含Circle.h之前包含GameApp.h。所以Circle在第一次遇到GameApp的定义时还没有定义。就像DanDan说的那样向前宣布Circle。
@詹姆斯是正确的 - Circle.h#包含GameApp.h,如原始编译器消息所示,而GameApp.h#包含Circle.h,通过思考不足的“include-all”包含。 h,但#include由于在Circle.h上包含多余的保护而无用。
在Includes.h中,您需要将#include "Circle.h"
移到#include "GameApp.h"
之前。更好的是,直接从GameApp.h中包含Circle.h。每个头文件应包含直接编译所需的所有内容。
我删除了C标签。把C放在这样的问题上是非常荒谬的。而且,这个班级没什么问题。看到实际的代码会很有用。 – Puppy 2010-07-28 19:33:21
** Includes.h **中包含** GameApp.h **吗?你的头文件是否包含守卫?你有圆形包容问题吗? – 2010-07-28 19:33:25
你确定你的Circle.h是一个有效的头文件 - 你是否成功地使用它编译过某些东西?也许你已经忘记了类声明结尾处的分号? – 2010-07-28 19:34:13