[SDL] forward decleration problem

Kostas Kostiadis kos at climaxgroup.com
Fri Jan 7 11:22:45 PST 2005

Nope...one at a time...to clarify, when I said:

> I have tried both
> struct SDL_MouseMotionEvent; and
> typedef struct MouseMotionEvent;

I ment I have tried both, one at a time (not both at the same time) ;-)

To answer your other question, I don't like including headers in header
files unless I have to.  It creates hude dependancy trees that on
some platforms (e.g. GameCube) are very problematic (especialy
on large projects).  So, as a habit, I prefer to use pointers and 
references in headers for things I can forward declare and then include
the relevant headers in the implementation files when I actualy need to
use these types.


-----Original Message-----
From: sdl-bounces+kos=climaxgroup.com at libsdl.org
[mailto:sdl-bounces+kos=climaxgroup.com at libsdl.org]On Behalf Of Benjamin
Sent: 07 January 2005 19:12
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] forward decleration problem


> I have a header that has pointers to SDL_MouseMotionEvent and
> SDL_MouseButtonEvent,
> so at the top of the header I'm trying to forward declare these (then in
> .cpp I include the
> appropriate header).

Um, this may be a stupid question, but what about including the SDL 
header(s) at the beginning of your headers? Is it really necessary to do 
forward declaration? Something like that is usually only used to work 
around circular declarations, and I doubt SDL code relies on things your 
code needs to declare first (though I could be wrong !-)

> I have tried both
> struct SDL_MouseMotionEvent; and
> typedef struct MouseMotionEvent;

Both, as in "at the same time"? What happens if you only declare
struct SDL_MouseMotionEvent;
and comment out the other relevant portions of your code?

In my opinion, the code should be
   struct SDL_MouseMotionEvent;
   typedef struct SDL_MouseMotionEvent SDL_MouseMotionEvent;
EXCEPT that there may be conflicts trying to pre-declare C structures in 
C++ without surronding
   extern "C" {
lines. But then again, I'm no expert in C++ name mangling...

Still, hope this helps,

   Ben Deutsch

SDL mailing list
SDL at libsdl.org

More information about the SDL mailing list