Direct Origin Code
#include <iostream> #include <windows.h>using namespace Std;class ref{protected:ref () {isloop = false;} virtual void update () {cout<< "Super loop" << Endl;} BOOL Isloop;public:void unscheduleupdate () {isloop = false;} void Scheduleupdate () {Isloop = true;} void Mainloop () {if (Isloop) this->update ();}}; Class MyClass:p ublic ref{public:virtual void Update () {cout << "this loop" << Endl;}}; int main (int argc, char* argv[]) {ref*ref = new myclass;ref->scheduleupdate (); for (;;) {cout << "loop" << Endl; Sleep (+); Ref->mainloop (); Ref->unscheduleupdate ();} return (0);}
The result is consistent with the Cocos scheduleupdate timer function,
This problem has been plagued for a long time because the C + + Foundation is less solid, and this function is a typical virtual function application
Study on COCOS2DX timer scheduleupdate