PDA

Visualizza la versione completa : [C++] Funzioni "friend" ed errore


jobv
21-01-2011, 09:32
Salve forum!

Non riesco a capire perché compilando il seguente codice ottengo questo errore:


giovanni@Ubuntu10:~/Scrivania$ gcc a.cpp
a.cpp: In member function ‘bool MPEGaudio::WantedSpec(SDL_AudioSpec*)’:
a.cpp:20: error: ‘Play_MPEGaudioSDL’ was not declared in this scope

Ecco il codice:



//a.h
#include <SDL/SDL.h>

class MPEGaudio {

friend void Play_MPEGaudioSDL(void *udata, Uint8 *stream, int len);
friend int Play_MPEGaudio(MPEGaudio *audio, Uint8 *stream, int len);
#ifdef THREADED_AUDIO
friend int Decode_MPEGaudio(void *udata);
#endif

public:

bool WantedSpec(SDL_AudioSpec *wanted);

private:
static const int bitrate[2][3][15],frequencies[2][3];
int stereobound,subbandnumber,inputstereo,outputstereo ;
int layer,protection,bitrateindex,padding,extendedmode ;
enum _mpegversion {mpeg1,mpeg2} version;
enum _mode {fullstereo,joint,dual,single} mode;
enum _frequency {frequency44100,frequency48000,frequency32000} frequency;
};

//a.cpp
#include <SDL/SDL.h>

#include "a.h"

bool
MPEGaudio:: WantedSpec(SDL_AudioSpec *wanted)
{
wanted->freq = frequencies[version][frequency];
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
wanted->format = AUDIO_S16LSB;
#else
wanted->format = AUDIO_S16MSB;
#endif
if ( outputstereo ) {
wanted->channels = 2;
} else {
wanted->channels = 1;
}
wanted->samples = 4096;
wanted->callback = Play_MPEGaudioSDL;
wanted->userdata = this;
return true;
}


Grazie!

jobv
21-01-2011, 10:34
Ho semplificato tutto per individuare l'errore...sicuramente è una cavolata ma proprio non capisco:



//a2.h

typedef struct SDL_AudioSpec {
//void (SDLCALL *callback)(void *userdata, uint8_t *stream, int len);
void (*callback)(void);

} SDL_AudioSpec;

class MPEGaudio {

//friend void Play_MPEGaudioSDL(void *udata, uint8_t *stream, int len);
friend void call(void);

public:

bool WantedSpec(SDL_AudioSpec *wanted);


};

//a2.cpp
#include "a2.h"

bool
MPEGaudio:: WantedSpec(SDL_AudioSpec *wanted)
{
wanted->callback = call;//Play_MPEGaudioSDL;

return true;
}

void call(void)
{}

shodan
21-01-2011, 12:27
Prova a mettere il prototipo prima della classe.



void Play_MPEGaudioSDL(void *udata, Uint8 *stream, int len);
class MPEGaudio { // etc...

jobv
21-01-2011, 16:06
Grazie mille!!!

é andata!

Loading