[Solved] ERROR: expected class-name before '' token

Started by
1 comment, last by pitxardo 14 years, 2 months ago
Hi! I'm having this error when I go to compile:
Quote: C:\...\Ciudadano.h|6|error: expected class-name before '{' token|
The code of Ciudadano.h:

#ifndef CIUDADANO_H_INCLUDED
#define CIUDADANO_H_INCLUDED

#include "Entidad.h"

class Ciudadano : public Entidad {

    private:
        int foto, trasla;
        Sprite *grafico;

    public:
        Ciudadano();
        ~Ciudadano();

        void renderizar();
};

#endif // CIUDADANO_H_INCLUDED





I tried to make a Foward Declaration, but like I suspected, it gives me error:
Quote: C:\...\Ciudadano.h|8|error: invalid use of undefined type `struct Entidad'| C:\...\Ciudadano.h|6|error: forward declaration of `struct Entidad'|
The code of Ciudadano.h with Foward Declaration:

#ifndef CIUDADANO_H_INCLUDED
#define CIUDADANO_H_INCLUDED

#include "Entidad.h"

class Entidad;

class Ciudadano : public Entidad {

    private:
        int foto, trasla;
        Sprite *grafico;

    public:
        Ciudadano();
        ~Ciudadano();

        void renderizar();
};

#endif // CIUDADANO_H_INCLUDED





The header of Entidad.h:

#ifndef ENTIDAD_H_INCLUDED
#define ENTIDAD_H_INCLUDED

#include "Universo.h"

class Entidad {

    protected:
        float pos_x, pos_y, size_w, size_h;

    public:
        Entidad();
        ~Entidad();

        void actualizar(float planeta_x, float planeta_y, float planeta_z, float tamano_planeta, float rotacion_planeta);

        float getX();

};

#endif // ENTIDAD_H_INCLUDED





I'm getting crazy trying to fix this error :( [Edited by - pitxardo on January 20, 2010 4:01:27 AM]
Advertisement
The name of your "Universo.h" header makes me think you may be running into problems associated with "master" header files.
Quote:Original post by jpetrie
The name of your "Universo.h" header makes me think you may be running into problems associated with "master" header files.


Thank you very much!!! Solved!!!

The problem was the include of Universo.h, like the article says.

Finally I changed my Entidad.h to:
#ifndef ENTIDAD_H_INCLUDED#define ENTIDAD_H_INCLUDED#include <stdlib.h>#include <iostream>class Entidad {    protected:        float pos_x, pos_y, size_w, size_h;    public:        Entidad();        ~Entidad();        void actualizar(float planeta_x, float planeta_y, float planeta_z, float tamano_planeta, float rotacion_planeta);        float getX();};#endif // ENTIDAD_H_INCLUDED


and now works fine! :-)

This topic is closed to new replies.

Advertisement