[Solved]Weird issue. Seriously need help.
Moderator: Coders of Rage
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
[Solved]Weird issue. Seriously need help.
Okay, so I have a game engine, with many many files and classes and it's coming along very well. Now, It seems that when I inherit from my CEntity class ( The base class for my hierarchy) like I have done many times before, the new object's header isn't able to be included to almost any headers except a select few, without causing a ton of errors all through the program. I've never encountered something like this before, the errors end up saying like "; expected after..." like I have syntax errors and I know I don't and also, certain errors say that my class names are unknown even though they worked fine before including the new header. I don't get it, i've inherited from my base class many times and It won't mess up if I don't include it, but still have it there. Also I can include it in a few other headers like I said, but most cause the error. Does anyone know this off the top their head? it seems like it's a big deal. Otherwise I can post code if needed.
Last edited by like80ninjas on Sat Feb 26, 2011 4:23 pm, edited 1 time in total.
Re: Weird issue. Seriously need help.
That sounds like a declaration issue (I may be wrong). Are you being sure to use header guards?like80ninjas wrote:Okay, so I have a game engine, with many many files and classes and it's coming along very well. Now, It seems that when I inherit from my CEntity class ( The base class for my hierarchy) like I have done many times before, the new object's header isn't able to be included to almost any headers except a select few, without causing a ton of errors all through the program. I've never encountered something like this before, the errors end up saying like "; expected after..." like I have syntax errors and I know I don't and also, certain errors say that my class names are unknown even though they worked fine before including the new header. I don't get it, i've inherited from my base class many times and It won't mess up if I don't include it, but still have it there. Also I can include it in a few other headers like I said, but most cause the error. Does anyone know this off the top their head? it seems like it's a big deal. Otherwise I can post code if needed.
If so, try a forward declaration. When you have two headers: A.h and B.h for example and the class in A.h needs to know of B.h and the class in B.h needs to know of A.h, then a forward declaration is required in one of the two files where you'd simply write: class A; instead of including the header file. You can declare the class as many times as you want without any worries, you just can't define it more than once.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Weird issue. Seriously need help.
Yes, I use:
and I also use forward declaration's as well. Maybe including it is causing something else to need a forward declaration? Is that possible? Would it hurt to forward declare every class that something uses?
Code: Select all
#ifndef WHATEVER_H
#define WHATEVER_H
//CODE HERE
#endif
Re: Weird issue. Seriously need help.
You typically don't want to do that ^^ (as far as I know), but I can't really see how it could hurt anything other than being deemed "bad style". The only other thing I can think, is that you forgot a semi-colon after a class declaration? That's all I can really think of, without any code at least?like80ninjas wrote:Yes, I use:
and I also use forward declaration's as well. Maybe including it is causing something else to need a forward declaration? Is that possible? Would it hurt to forward declare every class that something uses?Code: Select all
#ifndef WHATEVER_H #define WHATEVER_H //CODE HERE #endif
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Weird issue. Seriously need help.
See i'm actually very weary of my semi-colons following my class declarations because I had a huge bitchy error over it before that took forever to figure out haha.
Also like I said it can't be the class itself because when it is included in some things it compiles and runs gravy.
I'm not sure what exactly to post. I have 30+ files in my engine each with 100+ lines...
Also like I said it can't be the class itself because when it is included in some things it compiles and runs gravy.
I'm not sure what exactly to post. I have 30+ files in my engine each with 100+ lines...
- MrDeathNote
- ES Beta Backer
- Posts: 594
- Joined: Sun Oct 11, 2009 9:57 am
- Current Project: cocos2d-x project
- Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
- Programming Language of Choice: C/++
- Location: Belfast, Ireland
- Contact:
Re: Weird issue. Seriously need help.
Just for claritys sake do you mean #ifndef guards are bad practice or foward declaring everything?XianForce wrote:You typically don't want to do that ^^ (as far as I know), but I can't really see how it could hurt anything other than being deemed "bad style". The only other thing I can think, is that you forgot a semi-colon after a class declaration? That's all I can really think of, without any code at least?like80ninjas wrote:Yes, I use:
and I also use forward declaration's as well. Maybe including it is causing something else to need a forward declaration? Is that possible? Would it hurt to forward declare every class that something uses?Code: Select all
#ifndef WHATEVER_H #define WHATEVER_H //CODE HERE #endif
http://www.youtube.com/user/MrDeathNote1988
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
Re: Weird issue. Seriously need help.
forward declaration haha. I just recall a few people saying that you don't want to use forward declarations all the time when I asked about them a couple of years ago. As far as I know... You ALWAYS want to use header guards.... But then again, that could be wrong XDMrDeathNote wrote:Just for claritys sake do you mean #ifndef guards are bad practice or foward declaring everything?XianForce wrote:You typically don't want to do that ^^ (as far as I know), but I can't really see how it could hurt anything other than being deemed "bad style". The only other thing I can think, is that you forgot a semi-colon after a class declaration? That's all I can really think of, without any code at least?like80ninjas wrote:Yes, I use:
and I also use forward declaration's as well. Maybe including it is causing something else to need a forward declaration? Is that possible? Would it hurt to forward declare every class that something uses?Code: Select all
#ifndef WHATEVER_H #define WHATEVER_H //CODE HERE #endif
- adikid89
- Chaos Rift Cool Newbie
- Posts: 94
- Joined: Tue Apr 27, 2010 6:59 am
- Current Project: small tiny-mini projects
- Favorite Gaming Platforms: PC I guess...
- Programming Language of Choice: c++
Re: Weird issue. Seriously need help.
Why would forward declaring stuff be bad practice? And why would you possible forward declare something that you don't care about? Forward declaring can sometimes spare a useless #include and thus increase compile speed by a tad... Also I like using #pragma once .. as it looks a tad cleaner.
Also.. yeah post a little of the code that seems to be troublesome...
Also.. yeah post a little of the code that seems to be troublesome...
My first game C++/SDL Yoshi Combat! = http://www.youtube.com/watch?v=HQ9mMBEWSZg
==============================================================
==============================================================
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Weird issue. Seriously need help.
Check for circular dependencies. Forward declaration is the only way to solve this short of redesigning the relationships between classes (which may be a good idea if you've arrived at a circular dependency in the first place). This started showing up quite often when I had bitten off more than I could chew at the time with my own engine.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Weird issue. Seriously need help.
The only thing I can really think of is a circular dependency, but, i'm currently not using the class I had an issue with anymore, and working on cleaning out my code. Thanks for the suggestion guys, but I guess you can consider it "solved", if I run into this problem again I'll post the code back here.
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Weird issue. Seriously need help.
Tell me about it! Although, it's definitely a nice challenge to fix stuff within an enginelike80ninjas wrote:I'm not sure what exactly to post. I have 30+ files in my engine each with 100+ lines...
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Weird issue. Seriously need help.
What? That's wrong.XianForce wrote:forward declaration haha. I just recall a few people saying that you don't want to use forward declarations all the time when I asked about them a couple of years ago. As far as I know... You ALWAYS want to use header guards.... But then again, that could be wrong XDMrDeathNote wrote:Just for claritys sake do you mean #ifndef guards are bad practice or foward declaring everything?XianForce wrote:You typically don't want to do that ^^ (as far as I know), but I can't really see how it could hurt anything other than being deemed "bad style". The only other thing I can think, is that you forgot a semi-colon after a class declaration? That's all I can really think of, without any code at least?like80ninjas wrote:Yes, I use:
and I also use forward declaration's as well. Maybe including it is causing something else to need a forward declaration? Is that possible? Would it hurt to forward declare every class that something uses?Code: Select all
#ifndef WHATEVER_H #define WHATEVER_H //CODE HERE #endif
Using forward declarations whenever you can is a great practice. Whoever told you otherwise didn't know what the hell they're talking about.
Give me one compelling reason not to. Now consider the fact that you are literally reducing file dependencies and decreasing compile time when you DO.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: [Solved]Weird issue. Seriously need help.
Thanks for clearing that up Falco, I didn't know much about it personally, but it would seem logical that if it helps, and doesn't hurt, why not use it?