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

problem with headers and structs

Started by neonoblivion Dec 29, 2003 at 2:23 PM 5 replies 650+ views
Original Post
neonoblivion
neonoblivion
I''ve created the following structure in a header(basicstuff.h) typedef struct sphere{ float x, y, z, radias; bool inout; } sphere; but when I try to define another struct in entitys.h in which I have included basicstuff.h: typedef struct entity{ sphere collision; int state; int value,value2; } entity; It claims to be unable to recognise "sphere". I could just move sphere into entitys.h, but I don''t want to for structural reasons, Klaus
_buu_
_buu_
Assuming this is C++, why are you bothering with typedefs? struct foo; generally works for me..
allsorts46
allsorts46
It''d probrably work if you did it the other way round... have header B include header A instead. That doesn''t help you do it the way you want, but should at least work.
"The finger of blame has turned upon itself"
KershAtWork
KershAtWork
I did a test application with exactly what you did, and it worked for me. Email me if you want me to send you my code (jeff.kershner@mesa.afmc.af.mil).

Although this will work either way, the old C style method for defining structs should be like this:

typedef struct
{
float x, y, z, /*etc...*/
} sphere;

The sphere should not appear in both the typedef line as well as the end of the struct.


The C++ style should be like this:

struct sphere
{
float x, y, z, /*etc...*/
};


The problem must be somewhere else. Do you have #pragma once at the top of your header files or some other method to make sure that then are not defined multiple times?
/jk
Plasmadog
Plasmadog
I''ve never had to use typedef''d structs in this way so I could be wrong, but here are my thoughts. If you are working strictly in C then it should either be:

/* basicstuff.h */
typedef struct {
float x,y,z,radius;
bool inout;
} sphere;

/* entitys.h */
typedef struct {
sphere collision;
int state;
int value, value2;
} entity;


Or this:

/* basicstuff.h */
struct sphere{
float x,y,z,radius;
bool inout;
};

/* entitys.h */
struct entity{
struct sphere collision;
int state;
int value, value2;
};


In C++ however, it''s much simpler:

/* basicstuff.h */
struct sphere {
float x,y,z,radius;
bool inout;
};

/* entitys.h */
struct entity {
sphere collision;
int state;
int value, value2;
};


Hope this helps.
You are not the one beautiful and unique snowflake who, unlike the rest of us, doesn't have to go through the tedious and difficult process of science in order to establish the truth. You're as foolable as anyone else. And since you have taken no precautions to avoid fooling yourself, the self-evident fact that countless millions of humans before you have also fooled themselves leads me to the parsimonious belief that you have too.--Daniel Rutter

Topic Locked

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

Sign in to reply to this topic.