跨平台类的写法

来源:互联网 发布:苹果删除不了软件 编辑:程序博客网 时间:2024/05/22 14:24
跨平台类的写法
有如下代码
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
0 0