Cocos2d x 为什么类可以调用no static函数?

Cocos2d x 为什么类可以调用no static函数?,cocos2d-x,Cocos2d X,initWithColor函数不是静态函数,为什么我可以用cclayercolor调用它 bool GameOverLayer::init() { if (CCLayerColor::initWithColor(ccc4(255, 255, 255, 255))) { return true; } else { return false; } } GameOverLayer继承自CCLayerColor,initWithC

initWithColor函数不是静态函数,为什么我可以用cclayercolor调用它

bool GameOverLayer::init()
{
    if (CCLayerColor::initWithColor(ccc4(255, 255, 255, 255))) {
        return true;
    }
    else
    {
        return false;
    }
}

GameOverLayer继承自CCLayerColor,initWithColor函数是公共且非静态的,因此在代码中可以使用以下语句:

define initWithColor function as below code :
bool CCLayerColor::initWithColor(const ccColor4B& color)
{
   CCSize s = CCDirector::sharedDirector()->getWinSize();
   this->initWithColor(color, s.width, s.height);
   return true;
}
这意味着调用从所选父级继承的函数。
如果您不喜欢这种类型的呼叫,可以使用:

CCLayerColor::initWithColor(ccc4(255,255,255,255));
如果您想更多地了解这种类型的编程,请阅读更多关于继承和多重继承的内容。你可以从开始到结束

this->initWithColor(ccc4(255,255,255,255));