根据cocos2d-x的代理模式,仿写一遍。
class CCApplicationProtocol { public: virtual bool applicationDidFinishLaunching() = 0; }; class CCApplication :public CCApplicationProtocol { public: static CCApplication* instance ; CCApplication() { //这里的this是CCApplication子类里面的对象 instance = this; } ~CCApplication() { } void run() { applicationDidFinishLaunching(); } static CCApplication* getInstance() { return instance; } }; CCApplication* CCApplication::instance = NULL; /** * @brief The Android class * android 平台实现 */ class Android:private CCApplication { public: bool applicationDidFinishLaunching() { cout<<"this is android"<<endl; return true; } }; /** * @brief The Linux class * Linux 平台的实现 */ class Linux:private CCApplication { public: bool applicationDidFinishLaunching() { cout<<"this is Linux"<<endl; return true; } }; /** * @brief The Ios class * IOS 平台的实现 */ class Ios:private CCApplication { public: bool applicationDidFinishLaunching() { cout<<"this is IOS"<<endl; return true; } }; /** * @brief The Ios class * win32 平台的实现 */ class Windows:private CCApplication { public: bool applicationDidFinishLaunching() { cout<<"this is windows"<<endl; return true; } };
@H_502_10@Linux平台实现的调用(后面创建的对象会覆盖前面创建的对象)。
@H_502_10@IOS平台
@H_502_10@win32平台