ヘッダーで宣言された2つのc++クラスがあります。ベースは仮想メソッドを宣言し、2番目のクラスがそれをオーバーライドします。実装は.cppファイルにあります。
コードはかなり単純です
void DefendProperty::apply(Queue<Defend*>* defendQueue,
const Tool* toolSource, const Actor* actorSource, const Actor* defender) {
cout << "BASE" << endl;
}
void DefendPropertyPhysical::apply(Queue<Defend*>* defendQueue,
Tool* toolSource, const Actor* actorSource, const Actor* defender) {
cout << "CORRECT" << endl;
defendQueue->enqueue(new Defend(
DefendTypePhysical::TYPE,
new DamageValuesPhysical(
getRandomDouble(minDamageReduction, maxDamageReduction))
));
}
重要なのは、インスタンス化されたクラスをBと呼ぶと、CORRECTではなくBASEを出力するということです。この時点で何が起こっているのかわかりません。
クラスは、applyメソッドを持たない基本のToolPropertyタイプに格納されます。それらが呼び出されると、dynamic_castを使用してDefendPropertyタイプにタイプキャストされます。
dynamic_cast<DamageProperty*>(node->value)->apply(damageQueue, toolSource, actorSource);
どんな助けでもいただければ幸いです