私は変更できないstruct simple_instrを持っています。私はそれから派生した型を作成します。ポインタが派生型のインスタンスを指しているかどうかをどのようにして知ることができますか?
struct ComplexInstruction : simple_instr
{
ComplexInstruction(const simple_instr& simple) : simple_instr(simple)
{
}
bool isHead;
bool isTail;
bool isPreHeader;
};
私はsimple_instrのインスタンスが実際にComplexInstructionであるかどうかを伝えることができるようにしたいです。それがnull等しかった場合、私は ComplexInstruction* cInstr = static_cast<ComplexInstruction*>(current);
とチェックを使用してみましたが、問題はキャストが常に成功するということである、とcInstrがnullに等しいことはありません
ComplexInstruction comInstr = *current; // current is a pointer to a simple_instr
ComplexInstruction* cInstr = &comInstr;
:私はそうのようなComplexInstructionsを作成します。
これを行うには適切な方法はありますか?
基本クラスは多態性ですか? (つまり、仮想メンバーの機能はありますか?) –
残念ながら、 – Megatron