Silly c++ question

I must be doing something really obvious wrong…and i appologise in advance
if i am being stupid but basically i have a struct that is part of the gfx
engine header file which looks like this:

// watch for multiple inclusions
#ifndef GFX_h
#define GFX_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

struct Animation_Object
{
std::vector<SDL_Surface*> _animation;
std::vector _delays;
int _currentAnim; //What current animation are we playing?
long _timeStartedPlaying; //When did animation start playing?
};

and i am trying to use it in my game header file which looks like this:

// watch for multiple inclusions
#ifndef GAME_h
#define GAME_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

#define NUMBEROFMONSTERS 10

struct Collison_Object
{
Animation_Object _animation_Object;
SDL_Rect _coords;
SDL_Rect _rotCoords;
SDL_Rect _collisionArea;
SDL_Surface *surface;
SDL_Surface *rotSurface;
double rotateValue;
int alphaValue;
int offsetx,offsety; //Offset used to find centre of objects
};

(Note that main2.h is where everthing is being linke together):

// watch for multiple inclusions
#ifndef Main2_h
#define Main2_h

#include “SDL_mixer.h” //Used to load in music
#include “SDL_image.h” //Used to load in non bmp images
#include “SDL.h”
#include “Intro.h”
#include “Game.h”
#include “GraphicsEngine.h”

yet when i go to compile it says:

c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) : error
C2146: syntax error : missing ‘;’ before identifier '_animation_Object’
c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) : error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int
c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) : error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int

as if it cant see the Animation_object in the graphics engine header
file…i am very confused by this :confused: any suggestions? Cheers.

-James–
View this message in context: http://www.nabble.com/Silly-c%2B%2B-question-tf2116165.html#a5835104
Sent from the SDL forum at Nabble.com.

Off the top of my head I’d say that your Game.h file needs to #include
"GraphicsEngine.h" . Otherwise, how does your Collision_Object struct
know what an Animation_Object is?

Lilith

I must be doing something really obvious wrong…and i appologise in
advance
if i am being stupid but basically i have a struct that is part of
the gfx
engine header file which looks like this:

// watch for multiple inclusions
#ifndef GFX_h
#define GFX_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

struct Animation_Object
{
std::vector<SDL_Surface*> _animation;
std::vector _delays;
int _currentAnim; //What current
animation are we playing?
long _timeStartedPlaying; //When did animation
start playing?
};

and i am trying to use it in my game header file which looks like
this:

// watch for multiple inclusions
#ifndef GAME_h
#define GAME_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

#define NUMBEROFMONSTERS 10

struct Collison_Object
{
Animation_Object _animation_Object;
SDL_Rect _coords;
SDL_Rect _rotCoords;
SDL_Rect _collisionArea;
SDL_Surface *surface;
SDL_Surface *rotSurface;
double rotateValue;
int alphaValue;
int offsetx,offsety; //Offset used to find
centre of objects
};

(Note that main2.h is where everthing is being linke together):

// watch for multiple inclusions
#ifndef Main2_h
#define Main2_h

#include “SDL_mixer.h” //Used to load in music
#include “SDL_image.h” //Used to load in non
bmp images
#include “SDL.h”
#include “Intro.h”
#include “Game.h”
#include “GraphicsEngine.h”

yet when i go to compile it says:

c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31)
: error
C2146: syntax error : missing ‘;’ before identifier
’_animation_Object’
c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31)
: error
C4430: missing type specifier - int assumed. Note: C++ does not
support
default-int
c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31)
: error
C4430: missing type specifier - int assumed. Note: C++ does not
support>>> On 8/16/2006 at 10:50 AM, in message <5835104.post at talk.nabble.com>, darkplastic wrote:
default-int

as if it cant see the Animation_object in the graphics engine header
file…i am very confused by this :confused: any suggestions? Cheers.

-James

Or at least #include “GraphicsEngine.h” before you #include “Game.h”.
There’s no harm in doing what I suggested below other than a few extra
CPU cycles during the compile. That’s what the #ifndef’s are for.–
Lilith

On 8/16/2006 at 11:13 AM, in message <44E2FDD6.C7C3.00AE.0>, “Lilith Calbridge” <@Lilith_Calbridge> wrote:
Off the top of my head I’d say that your Game.h file needs to
#include
"GraphicsEngine.h" . Otherwise, how does your Collision_Object
struct
know what an Animation_Object is?

Lilith

On 8/16/2006 at 10:50 AM, in message <5835104.post at talk.nabble.com>, darkplastic wrote:

I must be doing something really obvious wrong…and i appologise
in
advance

if i am being stupid but basically i have a struct that is part of
the gfx
engine header file which looks like this:

// watch for multiple inclusions
#ifndef GFX_h
#define GFX_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

struct Animation_Object
{
std::vector<SDL_Surface*> _animation;
std::vector _delays;
int _currentAnim; //What current
animation are we playing?
long _timeStartedPlaying; //When did animation
start playing?
};

and i am trying to use it in my game header file which looks like
this:

// watch for multiple inclusions
#ifndef GAME_h
#define GAME_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

#define NUMBEROFMONSTERS 10

struct Collison_Object
{
Animation_Object _animation_Object;
SDL_Rect _coords;
SDL_Rect _rotCoords;
SDL_Rect _collisionArea;
SDL_Surface *surface;
SDL_Surface *rotSurface;
double rotateValue;
int alphaValue;
int offsetx,offsety; //Offset used to find
centre of objects
};

(Note that main2.h is where everthing is being linke together):

// watch for multiple inclusions
#ifndef Main2_h
#define Main2_h

#include “SDL_mixer.h” //Used to load in music
#include “SDL_image.h” //Used to load in non
bmp images
#include “SDL.h”
#include “Intro.h”
#include “Game.h”
#include “GraphicsEngine.h”

yet when i go to compile it says:

c:\documents and
settings\darkplastic\desktop!!game\game\Game.h(31)
: error

C2146: syntax error : missing ‘;’ before identifier
’_animation_Object’
c:\documents and
settings\darkplastic\desktop!!game\game\Game.h(31)
: error

C4430: missing type specifier - int assumed. Note: C++ does not
support
default-int
c:\documents and
settings\darkplastic\desktop!!game\game\Game.h(31)
: error

C4430: missing type specifier - int assumed. Note: C++ does not
support
default-int

as if it cant see the Animation_object in the graphics engine
header

file…i am very confused by this :confused: any suggestions? Cheers.

-James


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Not stupidly wrong, just a circular inclusion loop. Don’t sweat it.

Feel free to ignore my 2 cents, but I typically just have a small stdafx.h
header which contains:

#ifndef _STDAFX_H
#define _STDAFX_H

#include <sdl.h>
#include <sdl_mixer.h>
#include <sdl_image.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include

#endif

then your GFX.h would change to (just the top part):

#ifndef GFX_h
#define GFX_h

#include “stdafx.h”

//Animation_Object defined here as normal

#endif

and GAME.h would be modified to:

#ifndef GAME_h
#define GAME_h

#include “stdafx.h”

#define NUMBEROFMONSTERS 10

struct Collison_Object
{
Animation_Object _animation_Object;
SDL_Rect _coords;
SDL_Rect _rotCoords;
SDL_Rect _collisionArea;
SDL_Surface *surface;
SDL_Surface *rotSurface;
double rotateValue;
int alphaValue;
int offsetx,offsety; //Offset used to find centre of objects
};

//blah

#endif

then in your main2.h you can have:

#ifndef _MAIN2_H
#define _MAIN2_H

#include “stdafx.h”
#include “gfx.h”
#include “game.h”
#include “intro.h”

//rest is the same

That should be all you need to do…

hth,
Erik Yuzwa
Wazoo Enterprises Inc.
http://www.wazooinc.com>

I must be doing something really obvious wrong…and i appologise in
advance
if i am being stupid but basically i have a struct that is part of the gfx
engine header file which looks like this:

// watch for multiple inclusions
#ifndef GFX_h
#define GFX_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

struct Animation_Object
{
std::vector<SDL_Surface*> _animation;
std::vector _delays;
int _currentAnim; //What current animation are we playing?
long _timeStartedPlaying; //When did animation start playing?
};

and i am trying to use it in my game header file which looks like this:

// watch for multiple inclusions
#ifndef GAME_h
#define GAME_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

#define NUMBEROFMONSTERS 10

struct Collison_Object
{
Animation_Object _animation_Object;
SDL_Rect _coords;
SDL_Rect _rotCoords;
SDL_Rect _collisionArea;
SDL_Surface *surface;
SDL_Surface *rotSurface;
double rotateValue;
int alphaValue;
int offsetx,offsety; //Offset used to find centre of objects
};

(Note that main2.h is where everthing is being linke together):

// watch for multiple inclusions
#ifndef Main2_h
#define Main2_h

#include “SDL_mixer.h” //Used to load in music
#include “SDL_image.h” //Used to load in non bmp images
#include “SDL.h”
#include “Intro.h”
#include “Game.h”
#include “GraphicsEngine.h”

yet when i go to compile it says:

c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) :
error
C2146: syntax error : missing ‘;’ before identifier '_animation_Object’
c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) :
error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int
c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) :
error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int

as if it cant see the Animation_object in the graphics engine header
file…i am very confused by this :confused: any suggestions? Cheers.

-James


View this message in context:
http://www.nabble.com/Silly-c%2B%2B-question-tf2116165.html#a5835104
Sent from the SDL forum at Nabble.com.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

wazoo wrote:

Not stupidly wrong, just a circular inclusion loop. Don’t sweat it.

Feel free to ignore my 2 cents, but I typically just have a small stdafx.h
header which contains:

#ifndef _STDAFX_H
#define _STDAFX_H

#include <sdl.h>
#include <sdl_mixer.h>
#include <sdl_image.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include

#endif

then your GFX.h would change to (just the top part):

#ifndef GFX_h
#define GFX_h

#include “stdafx.h”

//Animation_Object defined here as normal

#endif

and GAME.h would be modified to:

#ifndef GAME_h
#define GAME_h

#include “stdafx.h”

#define NUMBEROFMONSTERS 10

struct Collison_Object
{
Animation_Object _animation_Object;
SDL_Rect _coords;
SDL_Rect _rotCoords;
SDL_Rect _collisionArea;
SDL_Surface *surface;
SDL_Surface *rotSurface;
double rotateValue;
int alphaValue;
int offsetx,offsety; //Offset used to find centre of objects
};

//blah

#endif

then in your main2.h you can have:

#ifndef _MAIN2_H
#define _MAIN2_H

#include “stdafx.h”
#include “gfx.h”
#include “game.h”
#include “intro.h”

//rest is the same

That should be all you need to do…

hth,
Erik Yuzwa
Wazoo Enterprises Inc.
http://www.wazooinc.com

I must be doing something really obvious wrong…and i appologise in
advance
if i am being stupid but basically i have a struct that is part of the
gfx
engine header file which looks like this:

// watch for multiple inclusions
#ifndef GFX_h
#define GFX_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

struct Animation_Object
{
std::vector<SDL_Surface*> _animation;
std::vector _delays;
int _currentAnim; //What current animation are we playing?
long _timeStartedPlaying; //When did animation start playing?
};

and i am trying to use it in my game header file which looks like this:

// watch for multiple inclusions
#ifndef GAME_h
#define GAME_h

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include
#include “Main2.h”

#define NUMBEROFMONSTERS 10

struct Collison_Object
{
Animation_Object _animation_Object;
SDL_Rect _coords;
SDL_Rect _rotCoords;
SDL_Rect _collisionArea;
SDL_Surface *surface;
SDL_Surface *rotSurface;
double rotateValue;
int alphaValue;
int offsetx,offsety; //Offset used to find centre of objects
};

(Note that main2.h is where everthing is being linke together):

// watch for multiple inclusions
#ifndef Main2_h
#define Main2_h

#include “SDL_mixer.h” //Used to load in music
#include “SDL_image.h” //Used to load in non bmp images
#include “SDL.h”
#include “Intro.h”
#include “Game.h”
#include “GraphicsEngine.h”

yet when i go to compile it says:

c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) :
error
C2146: syntax error : missing ‘;’ before identifier '_animation_Object’
c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) :
error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int
c:\documents and settings\darkplastic\desktop!!game\game\Game.h(31) :
error
C4430: missing type specifier - int assumed. Note: C++ does not support
default-int

as if it cant see the Animation_object in the graphics engine header
file…i am very confused by this :confused: any suggestions? Cheers.

-James


View this message in context:
http://www.nabble.com/Silly-c%2B%2B-question-tf2116165.html#a5835104


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Awesome that fixed it…i just moved all the constants to the new stdfx
file as well :slight_smile: and kept the main.h just for including internal header
files. Thanks man!

-James>> Sent from the SDL forum at Nabble.com.


View this message in context: http://www.nabble.com/Silly-c%2B%2B-question-tf2116165.html#a5836082
Sent from the SDL forum at Nabble.com.

struct Animation_Object
{

[…]

struct Collison_Object
{
Animation_Object _animation_Object;

“Animation_Object” is not a type. The full type name is
"struct Animation_Object". (At least this is so in C, must
be the same in C++.) Therefore, the last quoted line must
be

struct Animation_Object _animation_Object;

Or else, to avoid “struct”, try typedef’ing “struct
_Animation_Object” to “Animation_Object”:

typedef struct _Animation_Object {
/* Contents of Animation_Object struct. */
} Animation_Object;

And make sure GFX.h is included in Game.h.

HTH,
OlegOn Wed, Aug 16, 2006 at 08:50:43AM -0700, darkplastic wrote:

struct Animation_Object
{

[…]

struct Collison_Object
{
Animation_Object _animation_Object;

“Animation_Object” is not a type. The full type name is
"struct Animation_Object". (At least this is so in C, must
be the same in C++.) Therefore, the last quoted line must
be

struct Animation_Object _animation_Object;

Or else, to avoid “struct”, try typedef’ing “struct
_Animation_Object” to “Animation_Object”:

typedef struct _Animation_Object {
/* Contents of Animation_Object struct. */
} Animation_Object;

And make sure GFX.h is included in Game.h.

No, his code was correct, though I believe yours is valid C++ as well for
compatibility reasons. Types and structures are not in different namespaces
in C++, since it already adds a real namespace framework.

Cheers,
RicardoEm Quarta, 16 de Agosto de 2006 17:44, o Oleg Katsitadze escreveu:

On Wed, Aug 16, 2006 at 08:50:43AM -0700, darkplastic wrote:

HTH,
Oleg


Two wrongs don’t make a right, but three lefts do.