Jump to content
  • Advertisement
Sign in to follow this  
ahayweh

Strange header problems...

This topic is 4119 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just ran into a baffling problem with a header file(s). I need some of the types , definitions in a file, say player.h. For all other files that include this, there is no problem. But once I try including player.h in say sprite.h, some of the structs are being undefined. I always use the #ifndef/#endif... Any ideas? Does thing have anything to do with the order the files are #include'ed in? If so, then why?

Share this post


Link to post
Share on other sites
Advertisement
What exactly is the error? And you say u do ifndef/endif.. thats at the beginning and end of the header file?

Also what are the names of the structs? make sure they are not generic(as you prolly know already).

Also are you going to be using them as objects or just pointers?

EDIT: Also note that make sure yer define is not used twice(in different files).

--Brad

Share this post


Link to post
Share on other sites
Compiling...
kamikaze.cpp
e:\program files\microsoft visual studio\myprojects\retro_type\game.h(33) : error C2061: syntax error : identifier 'pPlayer_t'
e:\program files\microsoft visual studio\myprojects\retro_type\game.h(34) : error C2061: syntax error : identifier 'pPlayer_t'
main.cpp
e:\program files\microsoft visual studio\myprojects\retro_type\game.h(33) : error C2061: syntax error : identifier 'pPlayer_t'
e:\program files\microsoft visual studio\myprojects\retro_type\game.h(34) : error C2061: syntax error : identifier 'pPlayer_t'
e:\program files\microsoft visual studio\myprojects\retro_type\main.cpp(77) : error C2660: 'G_ProcessCannon' : function does not take 2 parameters

pPlayer_t is of type Player_t*, which is properly defined, and used elsewhere in the program. And the function is properly declared and defined ( and utilized ), with no problem until I try adding game.h to another header file... Yeah, no generic types either.

Share this post


Link to post
Share on other sites
Did you copy and paste your include guards? If you did you might have given two headers files the same defines which causes one not to be included properly.

Share this post


Link to post
Share on other sites
Nope, I put them all in manually ( __GAME_H__ and _PLAYER_H__ , __<filedesc>_H__ for each unique file ). I am researching the C2061 error, but still haven't come up w/anything...

Share this post


Link to post
Share on other sites
It sounds like you're using the headers in a way that causes circular references...

Using forward-declarations should solve the problems, i.e:


//PLAYER.H:
#include "sprite.h"
class sprite;

class player
{
//...your code
};


//SPRITE.H
#include "player.h"

class sprite
{
//...your code
};



Just a thought, may be or may not be the problem thou. :)

Share this post


Link to post
Share on other sites
Do you have any cyclical dependencies in your headers?

EDIT: As Rasmadrak noted. Although having your sprite class depend on your player class is an punishable offense in at least seven countries.

Share this post


Link to post
Share on other sites
Thanks for the forward dec tip. I am working on trying that... Agreed, about the backward sprite-player dependency. Here are the offending files :

I am trying to add the powerups, from the game.h file to the player struct. Note that the game.h include and last function prototype are commented out due to causing errors.



[Edited by - ahayweh on July 14, 2007 3:39:55 PM]

Share this post


Link to post
Share on other sites
Well, including the game.h header would first include (before defining anything) the player.h header, which would include the game.h header again—but the include guards would object to the second inclusion, yielding an empty file. Then, the compiler would encounter a function definition with a powerup argument, and notice that no such type has been defined yet.

The solution would be to move powerups to their own file, in order to break the circular dependency.

Share this post


Link to post
Share on other sites
Darn it. I thought it was working, but then I deleted the comments off the proptype, and the compiler isn't seeing the types in the other header.... Well, at least I can include the header w/o any errors and thats progress...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!