这是我的代码
#include "stdafx.h"**
class IPlayback
{
public:
virtual void createRenderStream() = 0;
};
class ICapture
{
public:
virtual void createCaptureStream() = 0;
};
class IAudioStackInterface
{
public:
virtual void createStream() = 0;
};
class CAudioClientInterface : public IAudioStackInterface,
public ICapture,
public IPlayback
{
void createCaptureStream()
{
printf("\n i am in createCaptureStream");
}
void createRenderStream()
{
printf("\n i am in createRenderStream");
}
void createStream()
{
printf("\n i am in createStream");
}
};
typedef IAudioStackInterface* PIAudioStackInterface;
typedef ICapture* PCapture;
typedef IPlayback* PIPlayback;
typedef void* PVOID;
int main()
{
PVOID pObj = new CAudioClientInterface();
PIPlayback pPlayBackInterfcace = (PIPlayback) pObj;
pPlayBackInterfcace->createRenderStream();
return 0;
}
我应该打印createRenderstream而我正在打印createStream吗?
答案 0 :(得分:5)
尝试
PIPlayback pPlayBackInterfcace = (PIPlayback)(CAudioClientInterface*) pObj;
您只能投放到void*
并返回原始类型CAudioClientInterface*
。转换为另一种类型是未定义的行为。