I am working with a function called CreateSourceVoice that takes a pointer to a pointer as its first argument. The definition is:
HRESULT CreateSourceVoice(IXAudio2SourceVoice **ppSourceVoice, ...);
The following code does not work. I get an error at the spot designated by the carets stating that the expression must be an l-value or a function designator.
class SourceVoice
{
public:
IXAudio2SourceVoice* GetSourceVoice() { return sourceVoice; }
private:
IXAudio2SourceVoice* sourceVoice;
};
SourceVoice musicVoice;
void SoundSystem::Play(Sound& sound)
{
XAudio2->CreateSourceVoice(&(musicVoice.GetSourceVoice()), ...);
^^^^^
}
I can easily fix this by creating another function called GetSourceVoiceAddress like below and it works fine.
class SourceVoice
{
public:
IXAudio2SourceVoice* GetSourceVoice() { return sourceVoice; }
IXAudio2SourceVoice** GetSourceVoiceAddress() { return &sourceVoice; }
private:
IXAudio2SourceVoice* sourceVoice;
};
SourceVoice musicVoice;
void SoundSystem::Play(Sound& sound)
{
XAudio2->CreateSourceVoice(musicVoice.GetSourceVoiceAddress(), ...);
}
Or, if I store it in another pointer variable, it works fine.
void SoundSystem::Play(Sound& sound)
{
IXAudio2SourceVoice* tempVoice = musicVoice.GetSourceVoice();
XAudio2->CreateSourceVoice(&tempVoice, ...);
}
My question is what is fundamentally wrong with the top example, and why do the bottom two examples work when it seems like they are all doing the same thing. I am vaguely familiar with r-values and l-values, but obviously not enough.