初学试试看cocos2dx的TestCPP框架(1)

先模拟一下实现

#include <iostream>
#include <string>

using namespace std;

class CCApplication
{
public:
	CCApplication() 
	{
		sm_pSharedApplication = this;
	}

	int run() {
		cout << "run() function, sm_pSharedApplication = " << sm_pSharedApplication << endl;
		return 0;
	}

	static CCApplication * sharedApplication()
	{
		return sm_pSharedApplication;
	}

protected:
	static CCApplication * sm_pSharedApplication;
};

CCApplication *CCApplication::sm_pSharedApplication = 0;

class CCDerivedCCApplication : CCApplication
{

};

int main()
{
	CCDerivedCCApplication app;
	CCApplication::sharedApplication()->run();
}

一个cocos2dx里面会包含一个的派生CCApplication对象。通过静态的父类指针调用非虚函数run...

你可能感兴趣的:(Cocos)