Ok... I'm stumped
Ok, I''ve included my own header file Sound.h in two cpp files. In the header file I''ve defined SOUND_H and when I go to include them I use
#ifndef SOUND_H
#include "Sound.h"
#endif
But it''s not working, its giving me build errors because thing are of course alreasy defined. I already checked the spelling and that I defined them properly. What am I doing wrong here?
Put this in sound.h at the top
#if !defined ( SOUND_H )
#define SOUND_H
....include all of sound.h here
#endif
Hi, in .cpp file simply include de .h file:
#include "Sound.h"
and in the Sound.h do this:
#ifndef SOUND_H
#define SOUND_H
// File code...
#endif
That''s it. It should work correctly.
Hope this helps.
Bye
#include "Sound.h"
and in the Sound.h do this:
#ifndef SOUND_H
#define SOUND_H
// File code...
#endif
That''s it. It should work correctly.
Hope this helps.
Bye
Inside sound.h itself put:
#ifndef SOUND_H
#define SOUND_H
blah blah blah
#endif
..........
Then in your source files, just include "sound.h"
See if that helps.
EDIT: Whoa, lots of replies there!
[edited by - Waverider on October 2, 2002 12:34:10 PM]
#ifndef SOUND_H
#define SOUND_H
blah blah blah
#endif
..........
Then in your source files, just include "sound.h"
See if that helps.
EDIT: Whoa, lots of replies there!
[edited by - Waverider on October 2, 2002 12:34:10 PM]
It's not what you're taught, it's what you learn.
---CUT---
You can also use the #pragma once directive, which has the same effect.
[edited by - Prototype on October 2, 2002 12:41:37 PM]
You can also use the #pragma once directive, which has the same effect.
[edited by - Prototype on October 2, 2002 12:41:37 PM]
October 02, 2002 11:46 AM
While we''re on the subject. Does anybody know if #pragma once is MSVC specific?
October 02, 2002 11:53 AM
Ok, I just tried #pragma once with gcc and got a warning saying it''s obsolete... So... yeah...
I tried putting my code in the #ifndef but it still doesn''t work.
These are the errors that I''m getting:
Linking...
Sound.obj : error LNK2005: "struct _DSBUFFERDESC dsbd" (?dsbd@@3U_DSBUFFERDESC@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct tWAVEFORMATEX pcmwf" (?pcmwf@@3UtWAVEFORMATEX@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct pcm_sound_typ * sound_fx" (?sound_fx@@3PAUpcm_sound_typ@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct IDirectSound * lpds" (?lpds@@3PAUIDirectSound@@A) already defined in main.obj
Debug/builder.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
builder.exe - 5 error(s), 0 warning(s)
Any Ideas...
These are the errors that I''m getting:
Linking...
Sound.obj : error LNK2005: "struct _DSBUFFERDESC dsbd" (?dsbd@@3U_DSBUFFERDESC@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct tWAVEFORMATEX pcmwf" (?pcmwf@@3UtWAVEFORMATEX@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct pcm_sound_typ * sound_fx" (?sound_fx@@3PAUpcm_sound_typ@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct IDirectSound * lpds" (?lpds@@3PAUIDirectSound@@A) already defined in main.obj
Debug/builder.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
builder.exe - 5 error(s), 0 warning(s)
Any Ideas...
Did you put the #define in after the ifndef?
Think about what you are trying to do here - if it isn''t defined, then include the file and define it, if its already defined, then ignore everything.
Think about what you are trying to do here - if it isn''t defined, then include the file and define it, if its already defined, then ignore everything.
yeah my code pretty much goes:
#ifndef WINDOWS_H
#include <windows.h>
#endif
#ifndef MMSYSTEM_H
#include <mmsystem.h>
#endif
#ifndef DSOUND_H
#include <dsound.h>
#endif
#ifndef SOUND_H
#define SOUND_H
#define DSVOLUME_TO_DB( volume ) ( ( DWORD )( -30*( 100 - volume ) ) )
#define MAX_SOUNDS 256
#define DSBCAPS_CTRLDEFAULT DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLFREQUENCY
// digital sound object state defines
#define SOUND_NULL 0 // " "
#define SOUND_LOADED 1
#define SOUND_PLAYING 2
#define SOUND_STOPPED 3
struct pcm_sound_typ
{
LPDIRECTSOUNDBUFFER dsbuffer;
int state;
int rate;
int size;
int id;
};
pcm_sound_typ sound_fx[ MAX_SOUNDS ];
LPDIRECTSOUND lpds;
DSBUFFERDESC dsbd;
WAVEFORMATEX pcmwf;
bool InitDS( HWND hwnd );
bool PlayDS( bool loopSound, int id );
bool StopDS( int id );
bool SetVolumeDS( int vol, int id );
bool SetFrequencyDS( int freq, int id );
bool SetPanDS( int pan, int id );
bool DeInitDS();
int Load_WAV( char* filename, int CONTROL_FLAGS = DSBCAPS_CTRLDEFAULT );
#endif
[edited by - zyroth on October 2, 2002 4:45:21 PM]
#ifndef WINDOWS_H
#include <windows.h>
#endif
#ifndef MMSYSTEM_H
#include <mmsystem.h>
#endif
#ifndef DSOUND_H
#include <dsound.h>
#endif
#ifndef SOUND_H
#define SOUND_H
#define DSVOLUME_TO_DB( volume ) ( ( DWORD )( -30*( 100 - volume ) ) )
#define MAX_SOUNDS 256
#define DSBCAPS_CTRLDEFAULT DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLFREQUENCY
// digital sound object state defines
#define SOUND_NULL 0 // " "
#define SOUND_LOADED 1
#define SOUND_PLAYING 2
#define SOUND_STOPPED 3
struct pcm_sound_typ
{
LPDIRECTSOUNDBUFFER dsbuffer;
int state;
int rate;
int size;
int id;
};
pcm_sound_typ sound_fx[ MAX_SOUNDS ];
LPDIRECTSOUND lpds;
DSBUFFERDESC dsbd;
WAVEFORMATEX pcmwf;
bool InitDS( HWND hwnd );
bool PlayDS( bool loopSound, int id );
bool StopDS( int id );
bool SetVolumeDS( int vol, int id );
bool SetFrequencyDS( int freq, int id );
bool SetPanDS( int pan, int id );
bool DeInitDS();
int Load_WAV( char* filename, int CONTROL_FLAGS = DSBCAPS_CTRLDEFAULT );
#endif
[edited by - zyroth on October 2, 2002 4:45:21 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement