跨平台类的写法
有如下代码
void AudioEngine::playMusic(const std::string& fileName,bool bLoop /* = false */)
{
stopMusic();
if (m_bgmEnabled)
{
#if (TARGET_PLATFORM == PLATFORM_WIN32)
AudioEngineWin::playBackgroundMusic(fileName.c_str(),bLoop);
#elif (TARGET_PLATFORM == PLATFORM_ANDROID)
AudioEngineAndroid::playBackgroundMusic(fileName.c_str(),bLoop);
#elif (TARGET_PLATFORM == PLATFORM_IOS)
AudioEngineIos::playBackgroundMusic(fileName.c_str(),bLoop);
#endif
}
}
实际上的写法应是
void AudioEngine::playMusic(const std::string& fileName,bool bLoop /* = false */)
{
stopMusic();
if (m_bgmEnabled)
{
AudioEngineCore::playBackgroundMusic(fileName.c_str(),bLoop);
}
}
在编译过程中根据不同平台,指定相应的cpp