Skip to main content
GameDev.net gamedev.net
🔒 Locked

Definition Error

Started by KodeNerd Jul 25, 2009 at 5:05 PM 1 replies 900+ views
Original Post
KodeNerd
KodeNerd
I have a small problem that appeared when I was doing something entirely unrelated to where the problem is. I have been working on something small with a friend who wanted to create a simple framework. I agreed to help him. Basically the message log is thus:

Compiling: Entity.cpp
In file included from C:\Users\George Gough\Documents\Seven Wishes\Source\Window.hpp:17,
from C:\Users\George Gough\Documents\Wishes\Source\Gui.hpp:13,
from C:\Users\George Gough\Documents\Wishes\Source\Renderer.hpp:20,
from C:\Users\George Gough\Documents\Wishes\Source\Entity.hpp:15,
from C:\Users\George Gough\Documents\Wishes\Source\Entity.cpp:9:
C:\Users\George Gough\Documents\Wishes\Source\Sprite.hpp:22: error: invalid use of undefined type `struct Entity'
C:\Users\George Gough\Documents\Wishes\Source\Sprite.hpp:20: error: forward declaration of `struct Entity'
In file included from C:\Users\George Gough\Documents\Wishes\Source\Gui.hpp:13,
from C:\Users\George Gough\Documents\Wishes\Source\Renderer.hpp:20,
from C:\Users\George Gough\Documents\Wishes\Source\Entity.hpp:15,
from C:\Users\George Gough\Documents\Wishes\Source\Entity.cpp:9:
C:\Users\George Gough\Documents\Wishes\Source\Window.hpp:20: error: invalid use of undefined type `struct Entity'
C:\Users\George Gough\Documents\Wishes\Source\Sprite.hpp:20: error: forward declaration of `struct Entity'
Process terminated with status 1 (0 minutes, 0 seconds)
4 errors, 0 warnings

Now the top of the file Sprite.hpp looks as thus:

#include <string>

#include "Entity.hpp"
#include "Vector.hpp"
#include "Texture.hpp"
#include "Renderer.hpp"

class Renderer;
class Entity;

class Sprite : public Entity {

I've tried moving the order of includes and forward declaring but neither work. I'm completely stumped and I can't build my project until this works.
------------George Gough
ScottMayo
ScottMayo
If Entity.h defines Entity, you don't need that forward reference "class Entity;".

I see two possibilities: either Entity.h doesn't really define Entity (check spelling, #ifdefs, etc.), or, bizarrely, the unneeded forward reference confused the compiler.

In many compilers you can turn on a flag (sometimes -EP or -P) that tells it to spit out the code after the preprocess step. It might help you find something turning off the definition.
KodeNerd
KodeNerd
I figured out what was going on and it took a few hours to figure it out.

I noticed that it was saying that the error was in the Entity.hpp file due to that line. That prompted me to look at all of my includes and I noticed that at some point I included the Sprite.hpp in a place where it would place itself before the full definition of the Entity class. Quite a hard to find error but it was found. Thank you for helping.
------------George Gough

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.