我想, 程序的最高境界是所有函数都是静态static的, 并且都是用tempale<class T>模板的。
这样复用性极高,和其他代码无关,代码量极少。
发现4种指针操作的方法
typedef struct _ClipingController
{
const char *itemText;
std::function<Node*()> callbackStencil;
std::function<Node*()> callbackContent;
} ClipingController;
ClipingController g_ClipingController[] =
{
{
"setStencil(grossini), addChild(shape)",
std::function<Node*()>(&HelloWorld::grossini),//函数指针
[]() {return HelloWorld::shape(); }//c++11新特性Lambda
},
{
"setStencil(shape), addChild(grossini)",
std::bind(&HelloWorld::shape), //如果是非静态函数就需要用这种方法
HelloWorld::grossini //直接返回指针地址
}
};
static int g_testCount = sizeof(g_ClipingController) / sizeof(g_ClipingController[0]);