[SDL] forward decleration problem

Kostas Kostiadis kos at climaxgroup.com
Mon Jan 10 00:53:07 PST 2005


I think you're missing the point...
The

#ifndef foo
#define foo
#endif

goes without saying...otherwise you get redefintion problems...
What I'm talking about is that with the GNU compiler you can't do this:

In foo.h

struct SDL_MouseMotionEvent;

class foo
{
	void SomeMethod(SDL_MouseMotionEvent* event);
};

which you should be able to...
Then in foo.cpp you can have

#include <SDL/SDL_event.h>
#include <SDL/SDL_mouse.h>

void foo::SomeMethod(SDL_MouseMotionEvent* event)
{
	// do something with event here
}

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


On Fri, 7 Jan 2005 19:22:45 -0000, Kostas Kostiadis <kos at climaxgroup.com>
wrote:
> 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.

With MSVC 6 and 7 you can put 

#pragma once

at the beginning of the header, and it will only be included once,
regardless of how many other files (or levels) include it.

If you're not using MSVC, I believe you can wrap your headers like this:

#ifndef MY_HEADER_H
#define MY_HEADER_H

... all your declarations etc here...

#endif /* MY_HEADER_H */

That way again it will only get included once. That should be portable
to any ANSI C++ compiler, and I believe any ANSI C compiler as well.

Hope this helps.

-Justin

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




More information about the SDL mailing list