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();

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2017-08-04 13:14  yxysuanfa  阅读(247)  评论(0编辑  收藏  举报