根据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; }};
AndroID平台实现的调用
linux平台实现的调用(后面创建的对象会覆盖前面创建的对象)。
IOS平台
win32平台
总结
以上是内存溢出为你收集整理的模拟cocos2d-x 代理模式全部内容,希望文章能够帮你解决模拟cocos2d-x 代理模式所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)