Page 1 of 1
[Solved]Weird issue. Seriously need help.
Posted: Fri Feb 25, 2011 11:31 pm
by like80ninjas
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.
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 12:01 am
by XianForce
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.
That sounds like a declaration issue (I may be wrong). Are you being sure to use header guards?
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.
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 12:06 am
by like80ninjas
Yes, I use:
Code: Select all
#ifndef WHATEVER_H
#define WHATEVER_H
//CODE HERE
#endif
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?
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 12:09 am
by XianForce
like80ninjas wrote:Yes, I use:
Code: Select all
#ifndef WHATEVER_H
#define WHATEVER_H
//CODE HERE
#endif
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?
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?
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 1:41 am
by like80ninjas
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...
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 11:42 am
by MrDeathNote
XianForce wrote:like80ninjas wrote:Yes, I use:
Code: Select all
#ifndef WHATEVER_H
#define WHATEVER_H
//CODE HERE
#endif
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?
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?
Just for claritys sake do you mean #ifndef guards are bad practice or foward declaring everything?
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 12:59 pm
by XianForce
MrDeathNote wrote:XianForce wrote:like80ninjas wrote:Yes, I use:
Code: Select all
#ifndef WHATEVER_H
#define WHATEVER_H
//CODE HERE
#endif
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?
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?
Just for claritys sake do you mean #ifndef guards are bad practice or foward declaring everything?
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 XD
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 1:16 pm
by adikid89
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...
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 2:01 pm
by dandymcgee
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.
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 4:23 pm
by like80ninjas
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.
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 4:52 pm
by GroundUpEngine
like80ninjas wrote:I'm not sure what exactly to post. I have 30+ files in my engine each with 100+ lines...
Tell me about it!
Although, it's definitely a nice challenge to fix stuff within an engine
Re: Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 7:35 pm
by Falco Girgis
XianForce wrote:MrDeathNote wrote:XianForce wrote:like80ninjas wrote:Yes, I use:
Code: Select all
#ifndef WHATEVER_H
#define WHATEVER_H
//CODE HERE
#endif
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?
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?
Just for claritys sake do you mean #ifndef guards are bad practice or foward declaring everything?
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 XD
What? That's wrong.
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.
Re: [Solved]Weird issue. Seriously need help.
Posted: Sat Feb 26, 2011 9:19 pm
by like80ninjas
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?