[SDL] Compile-time error when forward declaring Mix_Chunk

Gianfranco Berardi gberardi at gbgames.com
Thu Oct 5 21:25:34 PDT 2006


I recently started to learn how to use SDL_mixer, and so I followed a 
tutorial to get up to speed.  It seems most tutorials assume that you'd 
want to declare the pointer to Mix_Chunk right before the code you use 
it with, but I wanted to add a Mix_Chunk pointer as a member of a class.

Like I usually do when I add a pointer as a member, I forward declared 
the type and included the relevant header in the .cpp file for the 
class.    Specifically, I have a Game class, and I want to add a member:

Mix_Chunk * sound_;

So at the top of the header, I wrote:

struct Mix_Chunk;  // It could be class Mix_Chunk; The same error occurs

And in the game.cpp file, I include SDL.h and SDL_mixer.h.

When I try to compile, I get the following error:

g++ -c game.cpp -Wall -Wno-unknown-pragmas -Wno-format -g -DDEBUG 
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
/usr/include/SDL/SDL_mixer.h:90: error: conflicting declaration 'typedef 
struct Mix_Chunk Mix_Chunk'
game.h:36: error: 'Mix_Chunk' has a previous declaration as 'typedef 
struct Mix_Chunk Mix_Chunk'

Any idea why I can't forward declare Mix_Chunk?  I imagine it is 
something simple that I've missed, but I'm at a loss so far.

Thank for your time,
Gianfranco

-- 
GBGames' Blog, An Indie Game Developer's Somewhat Interesting Thoughts:
http://www.gbgames.com/blog
Staff Reviewer for Game Tunnel, the Independent Underground:
http://www.gametunnel.com




More information about the SDL mailing list