jex
jex

Reputation: 643

What's wrong here? - ISO C++ forbids declaration of 'Circle' with no type

maybe you can help me get this right. I have a class that is used to draw a circle, but the compiler sends me this message:

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

Here is the 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;
};

The Include.h looks like this:

//************************************************************************
//                              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

And the 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

Upvotes: 0

Views: 2999

Answers (6)

Drew Hall
Drew Hall

Reputation: 29065

In Includes.h, you need to move the #include "Circle.h" ahead of the #include "GameApp.h". Better yet, just include Circle.h directly from GameApp.h. Each header file should include everything it needs to compile directly.

Upvotes: 1

c-urchin
c-urchin

Reputation: 4534

@James is right -- Circle.h #includes GameApp.h, as shown by the original compiler message, and GameApp.h #includes Circle.h via the poorly-thought-out "include-all" Includes.h, but that #include is useless due to the redundant include guard on Circle.h

Upvotes: 0

Tim Kay
Tim Kay

Reputation: 31

Includes.h includes GameApp.h before including Circle.h. So Circle is not yet defined the first time it encounters the definition of GameApp. Like DanDan says forward declare Circle.

Upvotes: 1

strager
strager

Reputation: 90062

Do not use one-massive-include-to-include-everything (except for precompiled headers). It will almost certainly result in headaches.

Include what you need, and no more. It will solve your problem.

You can forward declare Circle, as DanDan suggested, but fixing your inclusion problem will help you more in the long run.

Upvotes: 9

mattben
mattben

Reputation: 76

I would check your make file to make sure the build is in the right order then, include both .h in each .h finial try combining the class if there both simple. good luck

Upvotes: 1

DanDan
DanDan

Reputation: 10562

You may have cyclic inclusion. Use a forward declaration:

class GameApp { 
class Cicle;
...

Upvotes: 2

Related Questions