I will not go into details about the singleton mode. I will go directly to the topic. We often can use the singleton mode in C ++, but in the cocos2d-x, the use of Singleton mode, whether you have encountered trouble, a variety of "could not resolve ", "error LNK" error. Next I will use an example to briefly introduce how the order example mode is written in the cocos2d-x: Here I write a class Global to store the unique variables that can be accessed globally in the game, this requires that we can access Global in any object at any time to read the unique variable header file stored in it as follows: [cpp] # ifndef _ GLOBAL_H _ # define _ GLOBAL_H _ # include "cocos2d. h "# include" StartLayer. h "class Global {public: StartLayer * startLayer; // stores the globally accessible unique variable static Global * toIns (); // returns the Global Object protected through this method :~ Global () ;};# endif Cpp file: [cpp] # include "Global. h "using namespace cocos2d; static Global * share = NULL; // This line is very important. The previous mistake we made was the C ++ habit. We put the variable declaration and initialization in the header file, cause error Global ::~ Global (void) {startLayer = NULL;} Global * Global: toIns () {if (! Share) {share = new Global (); CCLOG ("first") ;}cclog ("hello"); return share ;}you can also do this: the header file is as follows: [cpp] # ifndef _ GLOBAL_H _ # define _ GLOBAL_H _ # include "cocos2d. h "# include" StartLayer. h "class Global {public: StartLayer * startLayer; static Global * toIns (); static Global * share; // The static variable declaration is here protected :~ Global () ;};# endif CPP file: [cpp] # include "Global. h "using namespace cocos2d; // static Global * share = NULL; Global * Global: share = NULL; // put static variable initialization here, instead of in the header file Global ::~ Global (void) {startLayer = NULL;} Global * Global: toIns () {if (! Share) {share = new Global (); CCLOG ("first") ;}cclog ("hello"); return share ;}use the code in your project, have you learned? For the exception, you can also refer to the Code in the singleton (such as CCDirector) in the cocos2d-x, how they instance the singleton