2 自己编写:AppDelegate,CCApplication,CCApplicationProtocol

1 CCApplicationProtocol.h

/*

 * CCApplicationProtocol.h

 *

 *  Created on: 20141019

 *      Author: to-to

 */

 

#ifndef CCAPPLICATIONPROTOCOL_H_

#define CCAPPLICATIONPROTOCOL_H_

 

class CCApplicationProtocol {

public:

         CCApplicationProtocol();

         virtual ~CCApplicationProtocol();

 

         virtual bool applicationDidFinishLaunching()=0;

};

 

#endif /* CCAPPLICATIONPROTOCOL_H_ */

CCApplicationProtocol.cpp

/*

 * CCApplicationProtocol.cpp

 *

 *  Created on: 20141019

 *      Author: to-to

 */

#include "CCApplicationProtocol.h"

 

CCApplicationProtocol::CCApplicationProtocol() {

         //TODO:

}

 

CCApplicationProtocol::~CCApplicationProtocol() {

         //TODO:

}

CCApplication.h

/*

 * CCApplication.h

 *

 *  Created on: 20141019

 *      Author: to-to

 */

#ifndef CCAPPLICATION_H_

#define CCAPPLICATION_H_

 

#include "CCApplicationProtocol.h"

class CCApplication:public CCApplicationProtocol {

public:

         CCApplication();

         virtual ~CCApplication();

 

         int run();

 

         static CCApplication * sharedApplication();

         static CCApplication * sm_pSharedApplication;

};

 

#endif /* CCAPPLICATION_H_ */

CCApplication.cpp

/*

 * CCApplication.cpp

 *

 *  Created on: 20141019

 *      Author: to-to

 */

 

#include "CCApplication.h"

#include "stddef.h"

#include "iostream"

 

CCApplication * CCApplication::sm_pSharedApplication = NULL;

 

CCApplication::CCApplication() {

         sm_pSharedApplication = this;

}

 

CCApplication::~CCApplication() {

         //TODO

}

 

int CCApplication::run() {

         applicationDidFinishLaunching();

         return 1;

}

 

CCApplication * CCApplication::sharedApplication() {

         if (sm_pSharedApplication != NULL) {

                   return sm_pSharedApplication;

         }

}

AppDelegate.h

/*

 * AppDelegate.h

 *

 *  Created on: 20141019

 *      Author: to-to

 */

 

#ifndef APPDELEGATE_H_

#define APPDELEGATE_H_

 

#include "CCApplication.h"

 

class AppDelegate: public CCApplication {

public:

         AppDelegate();

         virtual ~AppDelegate();

 

         virtual bool applicationDidFinishLaunching();

};

 

#endif /* APPDELEGATE_H_ */

AppDelegate.cpp

/*

 * AppDelegate.cpp

 *

 *  Created on: 20141019

 *      Author: to-to

 */

#include "CCApplication.h"

#include "stddef.h"

#include "iostream"

 

CCApplication * CCApplication::sm_pSharedApplication = NULL;

 

CCApplication::CCApplication() {

         sm_pSharedApplication = this;

}

 

CCApplication::~CCApplication() {

         //TODO;

}

 

int CCApplication::run()

{

       applicationDidFinishLaunching();

       return 1;

}

 

CCApplication * CCApplication::sharedApplication() {

         if (sm_pSharedApplication != NULL) {

                   return sm_pSharedApplication;

         }

 

}

man.c

/*

 * main.cpp

 *

 *  Created on: 20141019

 *      Author: to-to

 */

 

#include <iostream>

#include "CCApplication.h"

#include "AppDelegate.h"

 

using namespace std;

 

int main() {

         AppDelegate app;

 

         AppDelegate *pp = &app;

         return CCApplication::sharedApplication()->run();

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。