[Solved]Weird issue. Seriously need help.

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

[Solved]Weird issue. Seriously need help.

Post 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.
Last edited by like80ninjas on Sat Feb 26, 2011 4:23 pm, edited 1 time in total.
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Weird issue. Seriously need help.

Post 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.
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Weird issue. Seriously need help.

Post 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?
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Weird issue. Seriously need help.

Post 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?
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Weird issue. Seriously need help.

Post 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...
User avatar
MrDeathNote
ES Beta Backer
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.

Post 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?
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"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
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Weird issue. Seriously need help.

Post 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
User avatar
adikid89
Chaos Rift Cool Newbie
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.

Post 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...
My first game C++/SDL Yoshi Combat! = http://www.youtube.com/watch?v=HQ9mMBEWSZg
==============================================================
Image
User avatar
dandymcgee
ES Beta Backer
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.

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Weird issue. Seriously need help.

Post 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.
User avatar
GroundUpEngine
Chaos Rift Devotee
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.

Post 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! :roll: Although, it's definitely a nice challenge to fix stuff within an engine ;)
User avatar
Falco Girgis
Elysian Shadows Team
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.

Post 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.
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: [Solved]Weird issue. Seriously need help.

Post 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?
Post Reply