【发布时间】:2015-03-13 13:36:29
【问题描述】:
我正在为 cocos2d-x 构建一个游戏,并想从父类调用子类方法。
class Parent {
*//do something
//How can i call method from subchild class here?*
}
class Child : Parent {
*//do something*
}
class SubChild : Child {
void functionToBeCalledFromParent();
}
【问题讨论】:
-
有一个简单的方法:在
Parent中使用虚函数,在SubChild中覆盖。 -
还有一个不太简单的方法:使用CRTP